<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="keywords" content="玖忆;文鹤;博客">
    
    <meta name="author" content="meteor">
    <!-- preconnect -->
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    
    
    <!--- Seo Part-->
    
    <link rel="canonical" href="https://wait-you.github.io/2023/06/19/java最佳实践/"/>
    <meta name="robots" content="index,follow">
    <meta name="googlebot" content="index,follow">
    <meta name="revisit-after" content="1 days">
    
        <meta name="description" content="# 最佳实践 # 初始化 Gradle 工程，引入单元测试 # 软件运行环境：  语言：Java17  最新的 LTS 版本 一些新的语言特性：  var 关键字来声明变量，Java 编译器可以在编译期间就去通过类型推断来判断出类型 record 类似于 Kotlin 中的 data class     构建工具：Gradle  不像 maven 完全是使用 XML 去编写的工程配置文件 可以在里">
<meta property="og:type" content="article">
<meta property="og:title" content="Java最佳实践">
<meta property="og:url" content="https://wait-you.github.io/2023/06/19/Java%E6%9C%80%E4%BD%B3%E5%AE%9E%E8%B7%B5/index.html">
<meta property="og:site_name" content="玖忆">
<meta property="og:description" content="# 最佳实践 # 初始化 Gradle 工程，引入单元测试 # 软件运行环境：  语言：Java17  最新的 LTS 版本 一些新的语言特性：  var 关键字来声明变量，Java 编译器可以在编译期间就去通过类型推断来判断出类型 record 类似于 Kotlin 中的 data class     构建工具：Gradle  不像 maven 完全是使用 XML 去编写的工程配置文件 可以在里">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="http://tuchuang.wenhe9.cn/img/202306181036725.png">
<meta property="og:image" content="http://tuchuang.wenhe9.cn/img/202306181420013.png">
<meta property="og:image" content="http://tuchuang.wenhe9.cn/img/202306181921279.png">
<meta property="og:image" content="http://tuchuang.wenhe9.cn/img/202306182028745.png">
<meta property="article:published_time" content="2023-06-19T04:41:10.000Z">
<meta property="article:modified_time" content="2023-07-02T03:35:26.579Z">
<meta property="article:author" content="meteor">
<meta property="article:tag" content="Java 最佳实践">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://tuchuang.wenhe9.cn/img/202306181036725.png">
    
    
    <!--- Icon Part-->
    <link rel="icon" type="image/png" href="/images/wenhe.png" sizes="192x192">
    <link rel="apple-touch-icon" sizes="180x180" href="/images/wenhe.png">
    <meta name="theme-color" content="#f1404b">
    <link rel="shortcut icon" href="/images/wenhe.png">
    <!--- Page Info-->
    
    <title>
        
            Java最佳实践 -
        
        玖忆
    </title>
    
<link rel="stylesheet" href="/css/style.css">

    
<link rel="stylesheet" href="/assets/fonts.css">

    <!--- Font Part-->
    
    
    
    

    <!--- Inject Part-->
    
    <script id="hexo-configurations">
    let Global = window.Global || {};
    Global.hexo_config = {"hostname":"wait-you.github.io","root":"/","language":"zh-CN"};
    Global.theme_config = {"articles":{"style":{"font_size":"16px","line_height":1.5,"image_border_radius":"14px","image_alignment":"center","image_caption":false,"link_icon":true},"word_count":{"enable":true,"count":true,"min2read":true},"author_label":{"enable":true,"auto":false,"list":[]},"code_block":{"copy":true,"style":"mac","font":{"enable":false,"family":null,"url":null}},"toc":{"enable":true,"max_depth":3,"number":false,"expand":true,"init_open":true},"copyright":true,"lazyload":true,"recommendation":{"enable":false,"title":"推荐阅读","limit":3,"placeholder":"http://tuchuang.wenhe9.cn/default-bg.jpg","skip_dirs":[]}},"colors":{"primary":"#f1404b","secondary":null},"global":{"fonts":{"chinese":{"enable":false,"family":null,"url":null},"english":{"enable":false,"family":null,"url":null}},"content_max_width":"1000px","sidebar_width":"210px","hover":{"shadow":true,"scale":false},"scroll_progress":{"bar":true,"percentage":true},"busuanzi_counter":{"enable":true,"site_pv":true,"site_uv":true,"post_pv":true},"pjax":true,"open_graph":true,"google_analytics":{"enable":false,"id":null}},"home_banner":{"enable":true,"style":"static","image":{"light":"http://tuchuang.wenhe9.cn/default-bg.jpg","dark":"http://tuchuang.wenhe9.cn/default-bg.jpg"},"title":"玖忆","subtitle":{"text":["我本微末凡尘、可也心向天空"],"hitokoto":{"enable":false,"api":"https://v1.hitokoto.cn"},"typing_speed":100,"backing_speed":80,"starting_delay":500,"backing_delay":1500,"loop":true,"smart_backspace":true},"text_color":{"light":"#fff","dark":"#d1d1b6"},"text_style":{"title_size":"2.8rem","subtitle_size":"1.5rem","line_height":1.2},"custom_font":{"enable":false,"family":null,"url":null},"social_links":{"enable":true,"links":{"github":"https://gitee.com/du-jinliang","instagram":null,"zhihu":null,"twitter":null,"email":"dujinliang9@163.com"}}},"plugins":{"feed":{"enable":false},"aplayer":{"enable":false,"type":"fixed","audios":[{"name":null,"artist":null,"url":null,"cover":null}]},"mermaid":{"enable":false,"version":"9.3.0"}},"version":"2.1.4","navbar":{"auto_hide":true,"color":{"left":"#f78736","right":"#367df7","transparency":35},"links":{"Home":{"path":"/","icon":"fa-regular fa-house"}},"search":{"enable":false,"preload":true}},"page_templates":{"friends_column":2,"tags_style":"blur"},"home":{"sidebar":{"enable":true,"position":"left","first_item":"menu","announcement":null,"links":null},"article_date_format":"auto","categories":{"enable":true,"limit":3},"tags":{"enable":true,"limit":3}}};
    Global.language_ago = {"second":"%s 秒前","minute":"%s 分钟前","hour":"%s 小时前","day":"%s 天前","week":"%s 周前","month":"%s 个月前","year":"%s 年前"};
    Global.data_config = {"masonry":false};
  </script>
    
    <!--- Fontawesome Part-->
    
<link rel="stylesheet" href="/fontawesome/fontawesome.min.css">

    
<link rel="stylesheet" href="/fontawesome/brands.min.css">

    
<link rel="stylesheet" href="/fontawesome/solid.min.css">

    
<link rel="stylesheet" href="/fontawesome/regular.min.css">

    
    
    
    
<meta name="generator" content="Hexo 6.3.0"></head>


<body>
<div class="progress-bar-container">
    
        <span class="scroll-progress-bar"></span>
    

    
        <span class="pjax-progress-bar"></span>
        <span class="pjax-progress-icon">
            <i class="fa-solid fa-circle-notch fa-spin"></i>
        </span>
    
</div>


<main class="page-container">

    

    <div class="main-content-container">

        <div class="main-content-header">
            <header class="navbar-container">
    
    <div class="navbar-content">
        <div class="left">
            
            <a class="logo-title" href="/">
                
                玖忆
                
            </a>
        </div>

        <div class="right">
            <!-- PC -->
            <div class="desktop">
                <ul class="navbar-list">
                    
                        
                            <li class="navbar-item">
                                <!-- Menu -->
                                <a class="" 
                                    href="/"  >
                                    
                                        
                                            <i class="fa-regular fa-house"></i>
                                        
                                        首页
                                    
                                </a>
                                <!-- Submenu -->
                                
                            </li>
                    
                    
                </ul>
            </div>
            <!-- Mobile -->
            <div class="mobile">
                
                <div class="icon-item navbar-bar">
                    <div class="navbar-bar-middle"></div>
                </div>
            </div>
        </div>
    </div>

    <!-- Mobile drawer -->
    <div class="navbar-drawer">
        <ul class="drawer-navbar-list">
            
                
                    <li class="drawer-navbar-item flex-center">
                        <a class="" 
                        href="/"  >
                             
                                
                                    <i class="fa-regular fa-house"></i>
                                
                                首页
                            
                        </a>
                    </li>
                    <!-- Submenu -->
                    
            

        </ul>
    </div>

    <div class="window-mask"></div>

</header>


        </div>

        <div class="main-content-body">

            

            <div class="main-content">

                
                    <div class="fade-in-down-animation">
    <div class="post-page-container">
        <div class="article-content-container">

            
            
                <div class="article-title">
                    <h1 class="article-title-regular">Java最佳实践</h1>
                </div>
            
                
            

            
                <div class="article-header">
                    <div class="avatar">
                        <img src="/images/wenhe.png">
                    </div>
                    <div class="info">
                        <div class="author">
                            <span class="name">meteor</span>
                            
                                <span class="author-label">Lv3</span>
                            
                        </div>
                        <div class="meta-info">
                            <div class="article-meta-info">
    <span class="article-date article-meta-item">
        <i class="fa-regular fa-pen-fancy"></i>&nbsp;
        <span class="desktop">2023-06-18 20:41:10</span>
        <span class="mobile">2023-06-18 20:41</span>
        <span class="hover-info">创建</span>
    </span>
    
        <span class="article-date article-meta-item">
            <i class="fa-regular fa-wrench"></i>&nbsp;
            <span class="desktop">2023-07-01 19:35:26</span>
            <span class="mobile">2023-07-01 19:35</span>
            <span class="hover-info">更新</span>
        </span>
    

    
        <span class="article-categories article-meta-item">
            <i class="fa-regular fa-folders"></i>&nbsp;
            <ul>
                
                    <li>
                        <a href="/categories/Java/">Java</a>&nbsp;
                    </li>
                
            </ul>
        </span>
    
    
        <span class="article-tags article-meta-item">
            <i class="fa-regular fa-tags"></i>&nbsp;
            <ul>
                
                    <li>
                        <a href="/tags/Java-%E6%9C%80%E4%BD%B3%E5%AE%9E%E8%B7%B5/">Java 最佳实践</a>&nbsp;
                    </li>
                
            </ul>
        </span>
    

    
    
    
    
        <span class="article-pv article-meta-item">
            <i class="fa-regular fa-eye"></i>&nbsp;<span id="busuanzi_value_page_pv"></span>
        </span>
    
</div>

                        </div>
                    </div>
                </div>
            

            <div class="article-content markdown-body">
                <h1 id="最佳实践"><a class="markdownIt-Anchor" href="#最佳实践">#</a> 最佳实践</h1>
<h2 id="初始化gradle工程引入单元测试"><a class="markdownIt-Anchor" href="#初始化gradle工程引入单元测试">#</a> 初始化 Gradle 工程，引入单元测试</h2>
<h3 id="软件运行环境"><a class="markdownIt-Anchor" href="#软件运行环境">#</a> 软件运行环境：</h3>
<ul>
<li>语言：Java17
<ul>
<li>最新的 LTS 版本</li>
<li>一些新的语言特性：
<ul>
<li>var 关键字来声明变量，Java 编译器可以在编译期间就去通过类型推断来判断出类型</li>
<li>record 类似于 Kotlin 中的 data class</li>
</ul>
</li>
</ul>
</li>
<li>构建工具：Gradle
<ul>
<li>不像 maven 完全是使用 XML 去编写的工程配置文件</li>
<li>可以在里面创建一些我们需要的构建脚本，更灵活</li>
</ul>
</li>
<li>module 方式管理代码库
<ul>
<li>当面对维护一个多工程的项目时，比如前端、后端、微服务可以在同一个窗口管理项目</li>
</ul>
</li>
</ul>
<h3 id="初始化gradle工程"><a class="markdownIt-Anchor" href="#初始化gradle工程">#</a> 初始化 Gradle 工程</h3>
<h4 id="使用idea创建gradle工程"><a class="markdownIt-Anchor" href="#使用idea创建gradle工程">#</a> 使用 idea 创建 Gradle 工程</h4>
<blockquote>
<p>使用 kotlin 作为 dsl，使用 gradle 构建 spring cloud 项目</p>
</blockquote>
<ul>
<li>
<p>一般使用 gradle 来管理项目时，build.gralde 的配置流程分为以下几个部分</p>
<ol>
<li>
<p>当前项目的整体信息，包括项目的语言、项目的描述，比如下面的配置中的 java 插件、项目信息和介绍、以及 jdk 的编码和版本</p>
</li>
<li>
<p>配置项目在构建过程中需要的构建脚本的依赖项和其他属性，可以指定需要使用的插件、依赖项和仓库等信息，比如下面的配置中的版本声明、依赖项的仓库地址、构建插件的依赖项</p>
</li>
<li>
<p>全局项目配置和子项目配置，其中全局项目配置包括根项目和子项目配置，项目配置可以指定插件、依赖管理、测试管理、仓库和一些配置信息，需要注意的是，当有子项目的时候，需要在父项目中配置 jar 的打包信息中的清单为 gradle，否则无法将多个模块打包到一起，可能会导致项目无法正确启动，可以在父项目中进行统一的依赖版本管理，需要注意的是，因为使用的是  <code>kotlin</code>  作为 gradle 的 <code>dsl</code> ，本身没有 <code>DependencyManagement</code> , 需要额外引入 <code>io.spring.dependency-management</code>  插件，这个插件提供了 <code>DependencyManagementExtension</code>  可以实现类似于  <code>groovy</code>  中的  <code>DependencyManagement</code>  的作用，然后在项目配置中使用 <code>configure&lt;DependencyManagementExtension&gt;</code>  使用该同一版本管理</p>
</li>
</ol>
</li>
<li>
<p>父工程</p>
<ul>
<li>
<div class="highlight-container" data-rel="Kotlin"><figure class="iseeu highlight kotlin"><figcaption data-lang="kotlin"></figcaption><table><tr><td data-num="1"></td><td><pre><span class="token keyword">import</span> io<span class="token punctuation">.</span>spring<span class="token punctuation">.</span>gradle<span class="token punctuation">.</span>dependencymanagement<span class="token punctuation">.</span>dsl<span class="token punctuation">.</span>DependencyManagementExtension</pre></td></tr><tr><td data-num="2"></td><td><pre><span class="token keyword">import</span> org<span class="token punctuation">.</span>gradle<span class="token punctuation">.</span>api<span class="token punctuation">.</span>tasks<span class="token punctuation">.</span>compile<span class="token punctuation">.</span>JavaCompile</pre></td></tr><tr><td data-num="3"></td><td><pre><span class="token keyword">import</span> org<span class="token punctuation">.</span>gradle<span class="token punctuation">.</span>api<span class="token punctuation">.</span>tasks<span class="token punctuation">.</span>javadoc<span class="token punctuation">.</span>Javadoc</pre></td></tr><tr><td data-num="4"></td><td><pre></pre></td></tr><tr><td data-num="5"></td><td><pre><span class="token comment">// 插件声明</span></pre></td></tr><tr><td data-num="6"></td><td><pre>plugins <span class="token punctuation">&#123;</span></pre></td></tr><tr><td data-num="7"></td><td><pre>    <span class="token function">id</span><span class="token punctuation">(</span><span class="token string-literal singleline"><span class="token string">"java"</span></span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="8"></td><td><pre><span class="token punctuation">&#125;</span></pre></td></tr><tr><td data-num="9"></td><td><pre></pre></td></tr><tr><td data-num="10"></td><td><pre><span class="token comment">// 项目信息和介绍</span></pre></td></tr><tr><td data-num="11"></td><td><pre>group <span class="token operator">=</span> <span class="token string-literal singleline"><span class="token string">"cn.wenhe9"</span></span></pre></td></tr><tr><td data-num="12"></td><td><pre>version <span class="token operator">=</span> <span class="token string-literal singleline"><span class="token string">"1.0.0-SNAPSHOT"</span></span></pre></td></tr><tr><td data-num="13"></td><td><pre>description <span class="token operator">=</span> <span class="token string-literal singleline"><span class="token string">"JDK新特性父工程"</span></span></pre></td></tr><tr><td data-num="14"></td><td><pre></pre></td></tr><tr><td data-num="15"></td><td><pre><span class="token comment">//java 编码和 jdk 版本设置</span></pre></td></tr><tr><td data-num="16"></td><td><pre>java <span class="token punctuation">&#123;</span></pre></td></tr><tr><td data-num="17"></td><td><pre>    tasks<span class="token punctuation">.</span>withType<span class="token operator">&lt;</span>JavaCompile<span class="token operator">></span> <span class="token punctuation">&#123;</span></pre></td></tr><tr><td data-num="18"></td><td><pre>        options<span class="token punctuation">.</span>encoding <span class="token operator">=</span> <span class="token string-literal singleline"><span class="token string">"UTF-8"</span></span></pre></td></tr><tr><td data-num="19"></td><td><pre>    <span class="token punctuation">&#125;</span></pre></td></tr><tr><td data-num="20"></td><td><pre>    tasks<span class="token punctuation">.</span>withType<span class="token operator">&lt;</span>Javadoc<span class="token operator">></span> <span class="token punctuation">&#123;</span></pre></td></tr><tr><td data-num="21"></td><td><pre>        options<span class="token punctuation">.</span>encoding <span class="token operator">=</span> <span class="token string-literal singleline"><span class="token string">"UTF-8"</span></span></pre></td></tr><tr><td data-num="22"></td><td><pre>    <span class="token punctuation">&#125;</span></pre></td></tr><tr><td data-num="23"></td><td><pre>    toolchain <span class="token punctuation">&#123;</span></pre></td></tr><tr><td data-num="24"></td><td><pre>        languageVersion<span class="token punctuation">.</span><span class="token function">set</span><span class="token punctuation">(</span>JavaLanguageVersion<span class="token punctuation">.</span><span class="token function">of</span><span class="token punctuation">(</span><span class="token number">17</span><span class="token punctuation">)</span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="25"></td><td><pre>    <span class="token punctuation">&#125;</span></pre></td></tr><tr><td data-num="26"></td><td><pre><span class="token punctuation">&#125;</span></pre></td></tr><tr><td data-num="27"></td><td><pre></pre></td></tr><tr><td data-num="28"></td><td><pre><span class="token comment">// 声明依赖版本信息、给插件引入依赖、仓库信息</span></pre></td></tr><tr><td data-num="29"></td><td><pre>buildscript <span class="token punctuation">&#123;</span></pre></td></tr><tr><td data-num="30"></td><td><pre>    extra<span class="token punctuation">[</span><span class="token string-literal singleline"><span class="token string">"springBootVersion"</span></span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string-literal singleline"><span class="token string">"3.0.0"</span></span></pre></td></tr><tr><td data-num="31"></td><td><pre>    extra<span class="token punctuation">[</span><span class="token string-literal singleline"><span class="token string">"springCloudVersion"</span></span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string-literal singleline"><span class="token string">"2022.0.3"</span></span></pre></td></tr><tr><td data-num="32"></td><td><pre>    extra<span class="token punctuation">[</span><span class="token string-literal singleline"><span class="token string">"springCloudAlibabaVersion"</span></span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string-literal singleline"><span class="token string">"2022.0.0.0-RC2"</span></span></pre></td></tr><tr><td data-num="33"></td><td><pre>    extra<span class="token punctuation">[</span><span class="token string-literal singleline"><span class="token string">"lombokVersion"</span></span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string-literal singleline"><span class="token string">"1.18.2"</span></span></pre></td></tr><tr><td data-num="34"></td><td><pre></pre></td></tr><tr><td data-num="35"></td><td><pre>    repositories <span class="token punctuation">&#123;</span></pre></td></tr><tr><td data-num="36"></td><td><pre>        <span class="token function">maven</span><span class="token punctuation">(</span>url <span class="token operator">=</span> <span class="token string-literal singleline"><span class="token string">"https://maven.aliyun.com/repository/public"</span></span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="37"></td><td><pre>        <span class="token function">maven</span><span class="token punctuation">(</span>url <span class="token operator">=</span> <span class="token string-literal singleline"><span class="token string">"https://mvnrepository.com"</span></span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="38"></td><td><pre>        <span class="token function">mavenLocal</span><span class="token punctuation">(</span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="39"></td><td><pre>        <span class="token function">mavenCentral</span><span class="token punctuation">(</span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="40"></td><td><pre>    <span class="token punctuation">&#125;</span></pre></td></tr><tr><td data-num="41"></td><td><pre></pre></td></tr><tr><td data-num="42"></td><td><pre>    <span class="token comment">// 引入 spring boot gradle 插件 管理 spring boot starter 依赖版本</span></pre></td></tr><tr><td data-num="43"></td><td><pre>    dependencies <span class="token punctuation">&#123;</span></pre></td></tr><tr><td data-num="44"></td><td><pre>        <span class="token function">classpath</span><span class="token punctuation">(</span><span class="token string-literal singleline"><span class="token string">"org.springframework.boot:spring-boot-gradle-plugin:</span><span class="token interpolation"><span class="token interpolation-punctuation punctuation">$&#123;</span><span class="token expression"><span class="token function">property</span><span class="token punctuation">(</span><span class="token string-literal singleline"><span class="token string">"springBootVersion"</span></span><span class="token punctuation">)</span></span><span class="token interpolation-punctuation punctuation">&#125;</span></span><span class="token string">"</span></span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="45"></td><td><pre>    <span class="token punctuation">&#125;</span></pre></td></tr><tr><td data-num="46"></td><td><pre><span class="token punctuation">&#125;</span></pre></td></tr><tr><td data-num="47"></td><td><pre></pre></td></tr><tr><td data-num="48"></td><td><pre><span class="token comment">// 所有项目设置 (包括根项目、子项目) 主要用于设置仓库信息、统一依赖版本管理</span></pre></td></tr><tr><td data-num="49"></td><td><pre>allprojects <span class="token punctuation">&#123;</span></pre></td></tr><tr><td data-num="50"></td><td><pre>    <span class="token function">apply</span><span class="token punctuation">(</span>plugin <span class="token operator">=</span> <span class="token string-literal singleline"><span class="token string">"java"</span></span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="51"></td><td><pre>    <span class="token function">apply</span><span class="token punctuation">(</span>plugin <span class="token operator">=</span> <span class="token string-literal singleline"><span class="token string">"idea"</span></span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="52"></td><td><pre>    <span class="token function">apply</span><span class="token punctuation">(</span>plugin <span class="token operator">=</span> <span class="token string-literal singleline"><span class="token string">"org.springframework.boot"</span></span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="53"></td><td><pre>    <span class="token function">apply</span><span class="token punctuation">(</span>plugin <span class="token operator">=</span> <span class="token string-literal singleline"><span class="token string">"io.spring.dependency-management"</span></span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="54"></td><td><pre></pre></td></tr><tr><td data-num="55"></td><td><pre>    repositories <span class="token punctuation">&#123;</span></pre></td></tr><tr><td data-num="56"></td><td><pre>        <span class="token function">maven</span><span class="token punctuation">(</span>url <span class="token operator">=</span> <span class="token string-literal singleline"><span class="token string">"https://maven.aliyun.com/repository/public"</span></span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="57"></td><td><pre>        <span class="token function">maven</span><span class="token punctuation">(</span>url <span class="token operator">=</span> <span class="token string-literal singleline"><span class="token string">"https://mvnrepository.com"</span></span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="58"></td><td><pre>        <span class="token function">mavenLocal</span><span class="token punctuation">(</span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="59"></td><td><pre>        <span class="token function">mavenCentral</span><span class="token punctuation">(</span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="60"></td><td><pre>    <span class="token punctuation">&#125;</span></pre></td></tr><tr><td data-num="61"></td><td><pre></pre></td></tr><tr><td data-num="62"></td><td><pre>    configure<span class="token operator">&lt;</span>DependencyManagementExtension<span class="token operator">></span> <span class="token punctuation">&#123;</span></pre></td></tr><tr><td data-num="63"></td><td><pre>        dependencies <span class="token punctuation">&#123;</span></pre></td></tr><tr><td data-num="64"></td><td><pre>            <span class="token function">dependency</span><span class="token punctuation">(</span><span class="token string-literal singleline"><span class="token string">"org.projectlombok:lombok:</span><span class="token interpolation"><span class="token interpolation-punctuation punctuation">$&#123;</span><span class="token expression"><span class="token function">property</span><span class="token punctuation">(</span><span class="token string-literal singleline"><span class="token string">"lombokVersion"</span></span><span class="token punctuation">)</span></span><span class="token interpolation-punctuation punctuation">&#125;</span></span><span class="token string">"</span></span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="65"></td><td><pre>        <span class="token punctuation">&#125;</span></pre></td></tr><tr><td data-num="66"></td><td><pre>        imports <span class="token punctuation">&#123;</span></pre></td></tr><tr><td data-num="67"></td><td><pre>            <span class="token function">mavenBom</span><span class="token punctuation">(</span><span class="token string-literal singleline"><span class="token string">"org.springframework.cloud:spring-cloud-dependencies:</span><span class="token interpolation"><span class="token interpolation-punctuation punctuation">$&#123;</span><span class="token expression"><span class="token function">property</span><span class="token punctuation">(</span><span class="token string-literal singleline"><span class="token string">"springCloudVersion"</span></span><span class="token punctuation">)</span></span><span class="token interpolation-punctuation punctuation">&#125;</span></span><span class="token string">"</span></span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="68"></td><td><pre>            <span class="token function">mavenBom</span><span class="token punctuation">(</span><span class="token string-literal singleline"><span class="token string">"com.alibaba.cloud:spring-cloud-alibaba-dependencies:</span><span class="token interpolation"><span class="token interpolation-punctuation punctuation">$&#123;</span><span class="token expression"><span class="token function">property</span><span class="token punctuation">(</span><span class="token string-literal singleline"><span class="token string">"springCloudAlibabaVersion"</span></span><span class="token punctuation">)</span></span><span class="token interpolation-punctuation punctuation">&#125;</span></span><span class="token string">"</span></span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="69"></td><td><pre>        <span class="token punctuation">&#125;</span></pre></td></tr><tr><td data-num="70"></td><td><pre>    <span class="token punctuation">&#125;</span></pre></td></tr><tr><td data-num="71"></td><td><pre></pre></td></tr><tr><td data-num="72"></td><td><pre></pre></td></tr><tr><td data-num="73"></td><td><pre>    <span class="token comment">// 在多模块项目下，需要将多个模块打包成一个 jar 文件，如果没有正确配置，可能会导致 jar 文件无法正确生成</span></pre></td></tr><tr><td data-num="74"></td><td><pre>    tasks<span class="token punctuation">.</span><span class="token function">jar</span> <span class="token punctuation">&#123;</span></pre></td></tr><tr><td data-num="75"></td><td><pre>        enabled <span class="token operator">=</span> <span class="token boolean">true</span></pre></td></tr><tr><td data-num="76"></td><td><pre>        manifest <span class="token punctuation">&#123;</span></pre></td></tr><tr><td data-num="77"></td><td><pre>            attributes<span class="token punctuation">[</span><span class="token string-literal singleline"><span class="token string">"provider"</span></span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string-literal singleline"><span class="token string">"gradle"</span></span></pre></td></tr><tr><td data-num="78"></td><td><pre>        <span class="token punctuation">&#125;</span></pre></td></tr><tr><td data-num="79"></td><td><pre>    <span class="token punctuation">&#125;</span></pre></td></tr><tr><td data-num="80"></td><td><pre></pre></td></tr><tr><td data-num="81"></td><td><pre><span class="token punctuation">&#125;</span></pre></td></tr><tr><td data-num="82"></td><td><pre></pre></td></tr><tr><td data-num="83"></td><td><pre><span class="token comment">// 子项目通用配置</span></pre></td></tr><tr><td data-num="84"></td><td><pre>subprojects <span class="token punctuation">&#123;</span></pre></td></tr><tr><td data-num="85"></td><td><pre>    <span class="token function">apply</span><span class="token punctuation">(</span>plugin <span class="token operator">=</span> <span class="token string-literal singleline"><span class="token string">"java"</span></span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="86"></td><td><pre>    <span class="token function">apply</span><span class="token punctuation">(</span>plugin <span class="token operator">=</span> <span class="token string-literal singleline"><span class="token string">"io.spring.dependency-management"</span></span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="87"></td><td><pre></pre></td></tr><tr><td data-num="88"></td><td><pre>    <span class="token comment">// 通用依赖</span></pre></td></tr><tr><td data-num="89"></td><td><pre>    dependencies <span class="token punctuation">&#123;</span></pre></td></tr><tr><td data-num="90"></td><td><pre>        <span class="token function">implementation</span><span class="token punctuation">(</span><span class="token string-literal singleline"><span class="token string">"org.projectlombok:lombok"</span></span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="91"></td><td><pre>            <span class="token function">testImplementation</span><span class="token punctuation">(</span><span class="token string-literal singleline"><span class="token string">"org.springframework.boot:spring-boot-starter-test"</span></span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="92"></td><td><pre>    <span class="token punctuation">&#125;</span></pre></td></tr><tr><td data-num="93"></td><td><pre></pre></td></tr><tr><td data-num="94"></td><td><pre>    <span class="token comment">// 在 test 类中使用 junit5</span></pre></td></tr><tr><td data-num="95"></td><td><pre>    tasks <span class="token punctuation">&#123;</span></pre></td></tr><tr><td data-num="96"></td><td><pre>        test <span class="token punctuation">&#123;</span></pre></td></tr><tr><td data-num="97"></td><td><pre>            <span class="token function">useJUnitPlatform</span><span class="token punctuation">(</span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="98"></td><td><pre>        <span class="token punctuation">&#125;</span></pre></td></tr><tr><td data-num="99"></td><td><pre>    <span class="token punctuation">&#125;</span></pre></td></tr><tr><td data-num="100"></td><td><pre><span class="token punctuation">&#125;</span></pre></td></tr><tr><td data-num="101"></td><td><pre><span class="token operator">&lt;</span><span class="token operator">!</span><span class="token operator">--</span>code￼<span class="token number">0</span><span class="token operator">--</span><span class="token operator">></span></pre></td></tr></table></figure></div></li>
</ul>
</li>
</ul>
<h4 id="使用命令行方式创建gradle工程"><a class="markdownIt-Anchor" href="#使用命令行方式创建gradle工程">#</a> 使用命令行方式创建 Gradle 工程</h4>
<blockquote>
<p>使用 Kotlin 作为 DSL 来定义 Gradle 的脚本，因为 Kotlin 是一个静态语言，相对于动态语言，它可以在编译期间有更多的编译器带来的提示</p>
</blockquote>
<ol>
<li>
<p>创建  <code>settings.gradle.kts</code></p>
</li>
<li>
<p>执行 <code>gradle wrapper [--gradle-version=7.5.1]</code>  命令， <code>gradle wrapper</code>  会帮我们把 gradle 去包一层用 gradlew 命令去代替 gradle 命令，这样的话，需要更新 gradle 版本的时候，只需要更新 wrapper 的配置文件即可，这样就可以在不同的版本里面去随意切换并我的 wrapper 被提交到代码仓库以后，其他的协同开发者他去拉取了仓库， 可以保证不同的人在本地构建使用的 Gradle 版本都是一致的</p>
</li>
<li>
<p>创建  <code> build.gradle.kts</code>  ，gradle 可以左很多事情，构建是他的做核心的工作，告诉我这个脚本如何去把我的源码去编译成字节码 ，然后构建成哪些 jar 包，以及他里面有哪些依赖，这些都是在 <code>build.gradle</code>  里面去定义的。gradle 包含很多插件，他预先帮我们设置了很多的 gradle task，比如 Java</p>
<ul>
<li>
<div class="highlight-container" data-rel="Kotlin"><figure class="iseeu highlight kotlin"><figcaption data-lang="kotlin"></figcaption><table><tr><td data-num="1"></td><td><pre>plugins <span class="token punctuation">&#123;</span></pre></td></tr><tr><td data-num="2"></td><td><pre>    java</pre></td></tr><tr><td data-num="3"></td><td><pre>    `java<span class="token operator">-</span>library` <span class="token comment">// 编写类库</span></pre></td></tr><tr><td data-num="4"></td><td><pre>    application <span class="token comment">// 应用 增加一些应用打包的应用构建的 task</span></pre></td></tr><tr><td data-num="5"></td><td><pre><span class="token punctuation">&#125;</span></pre></td></tr><tr><td data-num="6"></td><td><pre></pre></td></tr><tr><td data-num="7"></td><td><pre><span class="token operator">&lt;</span><span class="token operator">!</span><span class="token operator">--</span>code￼<span class="token number">1</span><span class="token operator">--</span><span class="token operator">></span></pre></td></tr></table></figure></div></li>
<li>
<p>导入依赖</p>
</li>
<li>
<div class="highlight-container" data-rel="Kotlin"><figure class="iseeu highlight kotlin"><figcaption data-lang="kotlin"></figcaption><table><tr><td data-num="1"></td><td><pre>dependencies <span class="token punctuation">&#123;</span></pre></td></tr><tr><td data-num="2"></td><td><pre>    <span class="token function">testImplementation</span><span class="token punctuation">(</span><span class="token string-literal singleline"><span class="token string">"org.junit.jupiter:junit-jupiter-api:5.9.3"</span></span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="3"></td><td><pre>    <span class="token function">testImplementation</span><span class="token punctuation">(</span><span class="token string-literal singleline"><span class="token string">"org.junit.jupiter:junit-jupiter-engine:5.9.3"</span></span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="4"></td><td><pre><span class="token punctuation">&#125;</span></pre></td></tr><tr><td data-num="5"></td><td><pre><span class="token operator">&lt;</span><span class="token operator">!</span><span class="token operator">--</span>code￼<span class="token number">2</span><span class="token operator">--</span><span class="token operator">></span></pre></td></tr></table></figure></div></li>
</ul>
</li>
<li>
<p>统一 Java 版本，如果不声明默认使用机器的 Java 版本</p>
<ul>
<li>
<div class="highlight-container" data-rel="Kotlin"><figure class="iseeu highlight kotlin"><figcaption data-lang="kotlin"></figcaption><table><tr><td data-num="1"></td><td><pre>java <span class="token punctuation">&#123;</span></pre></td></tr><tr><td data-num="2"></td><td><pre>    toolchain <span class="token punctuation">&#123;</span></pre></td></tr><tr><td data-num="3"></td><td><pre>        languageVersion<span class="token punctuation">.</span><span class="token function">set</span><span class="token punctuation">(</span>JavaLanguageVersion<span class="token punctuation">.</span><span class="token function">of</span><span class="token punctuation">(</span><span class="token number">17</span><span class="token punctuation">)</span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="4"></td><td><pre>    <span class="token punctuation">&#125;</span></pre></td></tr><tr><td data-num="5"></td><td><pre><span class="token punctuation">&#125;</span></pre></td></tr><tr><td data-num="6"></td><td><pre><span class="token operator">&lt;</span><span class="token operator">!</span><span class="token operator">--</span>code￼<span class="token number">3</span><span class="token operator">--</span><span class="token operator">></span></pre></td></tr></table></figure></div></li>
</ul>
</li>
</ol>
<h2 id="添加spring支持设置-git-hooks"><a class="markdownIt-Anchor" href="#添加spring支持设置-git-hooks">#</a> 添加 Spring 支持，设置 Git Hooks</h2>
<h3 id="导入依赖"><a class="markdownIt-Anchor" href="#导入依赖">#</a> 导入依赖</h3>
<p>当导入 springboot 依赖时往往需要重复写 starter 的版本，可以使用之前提到的 bom 文件的方式导入</p>
<ol>
<li>
<p>引入 springboot 插件</p>
<ul>
<li>
<div class="highlight-container" data-rel="Kotlin"><figure class="iseeu highlight kotlin"><figcaption data-lang="kotlin"></figcaption><table><tr><td data-num="1"></td><td><pre>plugins <span class="token punctuation">&#123;</span></pre></td></tr><tr><td data-num="2"></td><td><pre>    java</pre></td></tr><tr><td data-num="3"></td><td><pre>    <span class="token function">id</span><span class="token punctuation">(</span><span class="token string-literal singleline"><span class="token string">"org.springframework.boot"</span></span><span class="token punctuation">)</span> version <span class="token string-literal singleline"><span class="token string">"2.6.4"</span></span></pre></td></tr><tr><td data-num="4"></td><td><pre><span class="token punctuation">&#125;</span></pre></td></tr><tr><td data-num="5"></td><td><pre></pre></td></tr><tr><td data-num="6"></td><td><pre><span class="token operator">&lt;</span><span class="token operator">!</span><span class="token operator">--</span>code￼<span class="token number">4</span><span class="token operator">--</span><span class="token operator">></span></pre></td></tr></table></figure></div></li>
</ul>
</li>
<li>
<p>整体效果</p>
<ul>
<li>
<div class="highlight-container" data-rel="Kotlin"><figure class="iseeu highlight kotlin"><figcaption data-lang="kotlin"></figcaption><table><tr><td data-num="1"></td><td><pre><span class="token keyword">import</span> org<span class="token punctuation">.</span>springframework<span class="token punctuation">.</span>boot<span class="token punctuation">.</span>gradle<span class="token punctuation">.</span>plugin<span class="token punctuation">.</span>SpringBootPlugin</pre></td></tr><tr><td data-num="2"></td><td><pre></pre></td></tr><tr><td data-num="3"></td><td><pre>plugins <span class="token punctuation">&#123;</span></pre></td></tr><tr><td data-num="4"></td><td><pre>    java</pre></td></tr><tr><td data-num="5"></td><td><pre>    <span class="token function">id</span><span class="token punctuation">(</span><span class="token string-literal singleline"><span class="token string">"org.springframework.boot"</span></span><span class="token punctuation">)</span> version <span class="token string-literal singleline"><span class="token string">"2.6.4"</span></span></pre></td></tr><tr><td data-num="6"></td><td><pre><span class="token punctuation">&#125;</span></pre></td></tr><tr><td data-num="7"></td><td><pre></pre></td></tr><tr><td data-num="8"></td><td><pre>repositories <span class="token punctuation">&#123;</span></pre></td></tr><tr><td data-num="9"></td><td><pre>    <span class="token function">mavenCentral</span><span class="token punctuation">(</span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="10"></td><td><pre><span class="token punctuation">&#125;</span></pre></td></tr><tr><td data-num="11"></td><td><pre></pre></td></tr><tr><td data-num="12"></td><td><pre>dependencies <span class="token punctuation">&#123;</span></pre></td></tr><tr><td data-num="13"></td><td><pre>    <span class="token function">implementation</span><span class="token punctuation">(</span><span class="token function">platform</span><span class="token punctuation">(</span>SpringBootPlugin<span class="token punctuation">.</span>BOM_COORDINATES<span class="token punctuation">)</span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="14"></td><td><pre>    <span class="token function">implementation</span><span class="token punctuation">(</span><span class="token string-literal singleline"><span class="token string">"org.springframework.boot:spring-boot-starter"</span></span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="15"></td><td><pre>    <span class="token function">implementation</span><span class="token punctuation">(</span><span class="token string-literal singleline"><span class="token string">"org.springframework.boot:spring-boot-starter-web"</span></span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="16"></td><td><pre>    <span class="token function">implementation</span><span class="token punctuation">(</span><span class="token string-literal singleline"><span class="token string">"org.springframework.boot:spring-boot-starter-actuator"</span></span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="17"></td><td><pre>    <span class="token function">testImplementation</span><span class="token punctuation">(</span><span class="token function">platform</span><span class="token punctuation">(</span><span class="token string-literal singleline"><span class="token string">"org.junit:junit-bom:5.9.3"</span></span><span class="token punctuation">)</span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="18"></td><td><pre>    <span class="token function">testImplementation</span><span class="token punctuation">(</span><span class="token string-literal singleline"><span class="token string">"org.junit.jupiter:junit-jupiter-api"</span></span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="19"></td><td><pre>    <span class="token function">testImplementation</span><span class="token punctuation">(</span><span class="token string-literal singleline"><span class="token string">"org.junit.jupiter:junit-jupiter-engine"</span></span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="20"></td><td><pre>    <span class="token function">testImplementation</span><span class="token punctuation">(</span><span class="token string-literal singleline"><span class="token string">"org.springframework.boot:spring-boot-starter-test"</span></span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="21"></td><td><pre><span class="token punctuation">&#125;</span></pre></td></tr><tr><td data-num="22"></td><td><pre></pre></td></tr><tr><td data-num="23"></td><td><pre>java <span class="token punctuation">&#123;</span></pre></td></tr><tr><td data-num="24"></td><td><pre>    toolchain <span class="token punctuation">&#123;</span></pre></td></tr><tr><td data-num="25"></td><td><pre>        languageVersion<span class="token punctuation">.</span><span class="token function">set</span><span class="token punctuation">(</span>JavaLanguageVersion<span class="token punctuation">.</span><span class="token function">of</span><span class="token punctuation">(</span><span class="token number">17</span><span class="token punctuation">)</span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="26"></td><td><pre>    <span class="token punctuation">&#125;</span></pre></td></tr><tr><td data-num="27"></td><td><pre><span class="token punctuation">&#125;</span></pre></td></tr><tr><td data-num="28"></td><td><pre></pre></td></tr><tr><td data-num="29"></td><td><pre>tasks <span class="token punctuation">&#123;</span></pre></td></tr><tr><td data-num="30"></td><td><pre>    test <span class="token punctuation">&#123;</span></pre></td></tr><tr><td data-num="31"></td><td><pre>        <span class="token function">useJUnitPlatform</span><span class="token punctuation">(</span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="32"></td><td><pre>    <span class="token punctuation">&#125;</span></pre></td></tr><tr><td data-num="33"></td><td><pre><span class="token punctuation">&#125;</span></pre></td></tr><tr><td data-num="34"></td><td><pre></pre></td></tr><tr><td data-num="35"></td><td><pre><span class="token operator">&lt;</span><span class="token operator">!</span><span class="token operator">--</span>code￼<span class="token number">5</span><span class="token operator">--</span><span class="token operator">></span></pre></td></tr></table></figure></div></li>
</ul>
</li>
</ol>
<h3 id="设置-githooks"><a class="markdownIt-Anchor" href="#设置-githooks">#</a> 设置 GitHooks</h3>
<p>不管是任何的开发人员在本地进行提交代码的时候，测试总应该是通过了，我们不能允许没有通过测试的代码被提交到我们的远程仓库去。</p>
<p>可以使用 Git 的 Hooks 实现这个功能</p>
<p>.git 文件夹下有一个 hooks 文件夹里面有很多的示例文件，比如 pre-commit.sample，即在这个文件中写的 bash 脚本会在我们进行提交的时候被执行，如果脚本执行失败的话，那这次提交不会成功</p>
<p>通常在项目中建立一个 githooks 目录， 建立一个 pre-commit 文件</p>
<p><img  
                     lazyload
                     src="/images/loading.svg"
                     data-src="http://tuchuang.wenhe9.cn/img/202306181036725.png"
                      alt="image-20230618103634630"
                ></p>
<p>pre-commit 内容</p>
<div class="highlight-container" data-rel="Shell"><figure class="iseeu highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">usr/bin/env sh</span></span><br><span class="line"></span><br><span class="line">git stash -qku</span><br><span class="line">./gradlew clean check</span><br><span class="line">RESULT=$?</span><br><span class="line">git stash pop -q</span><br><span class="line">exit $RESULT</span><br></pre></td></tr></table></figure></div>
<p><code>git stash -qku</code>  是一个 Git 命令，用于将当前未提交的更改保存到一个临时区域中，以便稍后可以恢复这些更改。</p>
<p>其中， <code>-q</code>  参数表示在执行命令时不输出任何提示信息； <code>-k</code>  参数表示在执行  <code>git stash</code>  命令时，不保存已经被 Git 跟踪的文件（即忽略  <code>.gitignore</code>  文件中指定的文件）； <code>-u</code>  参数表示在执行  <code>git stash</code>  命令时，同时保存未被 Git 跟踪的文件。</p>
<p><code>git stash pop -q</code>  是一个 Git 命令，它的作用是将最近一次保存在 Git 存储区（stash）中的修改应用到当前分支，并从存储区中删除该次保存。其中  <code>-q</code>  选项表示以安静模式（quiet）运行，即不在控制台输出任何信息。</p>
<p>更改其为可执行文件</p>
<p>安装 gitHooks</p>
<ol>
<li>
<p>将这个文件 copy 到我们的.git 目录下的 hooks 文件夹下，之后只要成员提交代码 hooks 里面的代码都会被执行，但是当我们更新了这个命令，比如安全检查、安全代码扫描，那么所有成员都需要重新将这个文件 copy 到目录下</p>
</li>
<li>
<p>比较推荐的是 直接将 git 的 hooks 文件夹配置到该文件夹下</p>
<ul>
<li>
<div class="highlight-container" data-rel="Shell"><figure class="iseeu highlight shell"><figcaption data-lang="Bash"></figcaption><table><tr><td data-num="1"></td><td><pre><span class="token function">git</span> config core.hooksPath githooks</pre></td></tr><tr><td data-num="2"></td><td><pre><span class="token operator">&lt;</span><span class="token operator">!</span>--code￼7--<span class="token operator">></span></pre></td></tr></table></figure></div></li>
</ul>
</li>
</ol>
<p>设计仓储接口</p>
<div class="highlight-container" data-rel="Java"><figure class="iseeu highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">interface</span> <span class="title class_">QuestionRepository</span> <span class="keyword">extends</span> <span class="title class_">JpaRepository</span>&lt;Question, String&gt; &#123;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></div>
<h3 id="测试"><a class="markdownIt-Anchor" href="#测试">#</a> 测试</h3>
<p>此时我们只需要测试仓储层的方法，所以可以用 <code>DataJpaTest</code>  这样一个注解来只启动跟 data-jpa 相关的 bean, 这样的话可以使我们的测试更生资源、更快速得去完成测试</p>
<p>引入数据库驱动包</p>
<h4 id="数据库迁移"><a class="markdownIt-Anchor" href="#数据库迁移">#</a> 数据库迁移</h4>
<p>引入 flyway 组件</p>
<ul>
<li>
<p>数据库的迁移或者 data 的 migration</p>
</li>
<li>
<p>我们可以比较方便的去定义我们每一次数据库的 schema 的变更，通过版本管理的方式，在每次启动应用的时候，他会去构建我们的数据库的 schema</p>
</li>
<li>
<p>在资源目录下定义 db/migration 文件夹，在此目录下定义 sql 脚本</p>
<ul>
<li>
<p>​	<img  
                     lazyload
                     src="/images/loading.svg"
                     data-src="http://tuchuang.wenhe9.cn/img/202306181420013.png"
                      alt="image-20230618142008933"
                ></p>
</li>
<li>
<div class="highlight-container" data-rel="Sql"><figure class="iseeu highlight sql"><figcaption data-lang="SQL"></figcaption><table><tr><td data-num="1"></td><td><pre><span class="token keyword">create</span> <span class="token keyword">table</span> question</pre></td></tr><tr><td data-num="2"></td><td><pre><span class="token punctuation">(</span></pre></td></tr><tr><td data-num="3"></td><td><pre>    id           <span class="token keyword">serial</span> <span class="token keyword">primary</span> <span class="token keyword">key</span><span class="token punctuation">,</span></pre></td></tr><tr><td data-num="4"></td><td><pre>    questionerId <span class="token keyword">text</span> <span class="token operator">not</span> <span class="token boolean">null</span><span class="token punctuation">,</span></pre></td></tr><tr><td data-num="5"></td><td><pre>    title        <span class="token keyword">text</span> <span class="token operator">not</span> <span class="token boolean">null</span><span class="token punctuation">,</span></pre></td></tr><tr><td data-num="6"></td><td><pre>    detail       <span class="token keyword">text</span></pre></td></tr><tr><td data-num="7"></td><td><pre><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="8"></td><td><pre><span class="token operator">&lt;</span><span class="token operator">!</span><span class="token comment">--code￼9--></span></pre></td></tr></table></figure></div></li>
</ul>
</li>
</ul>
<h4 id="测试容器"><a class="markdownIt-Anchor" href="#测试容器">#</a> 测试容器</h4>
<p>但是 application.yml 只是我们在运行期间它指定的这个数据源，如果我们想要在测试环境下去指定数据源，测试环境仍然是无法连接到这个数据库的，并且我们也不应该让我们的测试去依赖一个我们本地机器上的数据库</p>
<ol>
<li>
<p>spring 默认的会有一个 H2 的数据库，h2 是一个 <code>in-memory</code>  的数据库，他会在数据库中模拟 postgres 运行</p>
<ul>
<li>比较简单</li>
<li>并且不需要额外的其他依赖，就可以立刻启动这个数据库</li>
<li>但是 H2 毕竟是另外一种数据库，他并不是我们实际生产中的数据库，两种数据库的实现方式可能是完全不同的，那他有很多的语法的支持以及查询的效果都可能不一样，可能会导致我们在测试里面可以通过的代码到实际生产中却有其他的 bug</li>
</ul>
</li>
<li>
<p>使用一个 叫做 test-containers 框架</p>
<ul>
<li>
<p>帮助我们在启动测试的时候通过 java-docker 这样一个库连接到本地的 docker-socks 上，并且通过 docker 去启动一个对应的容器，然后在测试期间去连接这个容器进行我们的测试，这个容器可以是一个真实的 mysql 容器，运行结束以后这个容器就会销毁</p>
</li>
<li>
<div class="highlight-container" data-rel="Kotlin"><figure class="iseeu highlight kotlin"><figcaption data-lang="kotlin"></figcaption><table><tr><td data-num="1"></td><td><pre><span class="token function">testImplementation</span><span class="token punctuation">(</span><span class="token string-literal singleline"><span class="token string">"org.testcontainers:testcontainers:1.16.3"</span></span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="2"></td><td><pre>    <span class="token function">testImplementation</span><span class="token punctuation">(</span><span class="token string-literal singleline"><span class="token string">"org.testcontainers:mysql:1.16.3"</span></span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="3"></td><td><pre><span class="token operator">&lt;</span><span class="token operator">!</span><span class="token operator">--</span>code￼<span class="token number">10</span><span class="token operator">--</span><span class="token operator">></span></pre></td></tr><tr><td data-num="4"></td><td><pre></pre></td></tr><tr><td data-num="5"></td><td><pre><span class="token operator">-</span> 每次编写仓储测试的时候都需要引入三个注解</pre></td></tr><tr><td data-num="6"></td><td><pre></pre></td></tr><tr><td data-num="7"></td><td><pre>  <span class="token operator">-</span> ```java</pre></td></tr><tr><td data-num="8"></td><td><pre>    <span class="token annotation builtin">@DataJpaTest</span> <span class="token comment">//jpa 测试</span></pre></td></tr><tr><td data-num="9"></td><td><pre>    <span class="token annotation builtin">@Import</span><span class="token punctuation">(</span>DatabaseTestConfiguration<span class="token punctuation">.</span>class<span class="token punctuation">)</span> <span class="token comment">// 引入容器和自定义数据源配置</span></pre></td></tr><tr><td data-num="10"></td><td><pre>    <span class="token annotation builtin">@AutoConfigureTestDatabase</span><span class="token punctuation">(</span>replace <span class="token operator">=</span> NONE<span class="token punctuation">)</span> <span class="token comment">// 排除 spring 默认的 testDatabase</span></pre></td></tr><tr><td data-num="11"></td><td><pre>    <span class="token operator">&lt;</span><span class="token operator">!</span><span class="token operator">--</span>code￼<span class="token number">11</span><span class="token operator">--</span><span class="token operator">></span></pre></td></tr></table></figure></div></li>
</ul>
</li>
</ol>
<p>完整测试类</p>
<div class="highlight-container" data-rel="Java"><figure class="iseeu highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@JpaRepositoryTest</span></span><br><span class="line"><span class="keyword">class</span> <span class="title class_">RequisitionRepositoryTest</span> &#123;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Autowired</span></span><br><span class="line">    <span class="keyword">private</span> QuestionRepository questionRepository;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 测试仓储接口能够正确保存question并注入id</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="meta">@Test</span></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">repository_should_successfully_save_question</span><span class="params">()</span> &#123;</span><br><span class="line">        <span class="type">var</span> <span class="variable">question</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">Question</span>(<span class="string">&quot;UID_0001&quot;</span>, <span class="string">&quot;A test title&quot;</span>, <span class="string">&quot;A test detail&quot;</span>);</span><br><span class="line"></span><br><span class="line">        <span class="type">var</span> <span class="variable">savedQuestion</span> <span class="operator">=</span> questionRepository.save(question);</span><br><span class="line"></span><br><span class="line">        assertThat(savedQuestion.getId(), is(notNullValue()));</span><br><span class="line">        assertThat(savedQuestion.getQuestionerId(), equalTo(question.getQuestionerId()));</span><br><span class="line">        assertThat(savedQuestion.getTitle(), equalTo(question.getTitle()));</span><br><span class="line">        assertThat(savedQuestion.getDetail(), equalTo(question.getDetail()));</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></div>
<h2 id="代码静态检查测试业务方法"><a class="markdownIt-Anchor" href="#代码静态检查测试业务方法">#</a> 代码静态检查，测试业务方法</h2>
<h3 id="通用配置和环境配置分离"><a class="markdownIt-Anchor" href="#通用配置和环境配置分离">#</a> 通用配置和环境配置分离</h3>
<p>项目的 Spring 配置文件 <code>application.yml</code> , 这个文件中，我们之前配置了数据库的地址以及用户名密码，并且这个文件会被 Git 提交到远程仓库，但这种作法是不被推荐的</p>
<ul>
<li>对于代码库，他应该是一个与环境无关的纯代码的库</li>
<li>而配置文件有很多配置是与环境相关的，比如说数据库地址，数据库用户名和密码，在不同的开发手中，他的本机端口可能不是 3306，用户名密码不同</li>
<li>运行在测试环境和生产环境中的代码，，那他使用的配置也不会是现在配置的这一套东西，这一段配置理论上来说，不应该被提交到远程，</li>
</ul>
<p>通常来讲我们会新建一个本地配置，将环境相关配置放在本地配置文件中，这个文件我们是不希望被提交到远程仓库的，我们应该在.gitignore 里面去添加这个文件</p>
<div class="highlight-container" data-rel="Yml"><figure class="iseeu highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">### idea</span></span><br><span class="line"><span class="string">/.idea</span></span><br><span class="line"><span class="string">*.iml</span></span><br><span class="line"><span class="string">*.ipr</span></span><br><span class="line"><span class="string">/out</span></span><br><span class="line"></span><br><span class="line"><span class="comment">### gradle</span></span><br><span class="line"><span class="string">/.gradle</span></span><br><span class="line"><span class="string">/build</span></span><br><span class="line"></span><br><span class="line"><span class="comment">### Environment Configuration</span></span><br><span class="line"><span class="string">application-*.yml</span></span><br></pre></td></tr></table></figure></div>
<p>向仓库中提交一个可以供参考的模板配置文件，只是去指定一个模板，而不是让不同的开发使用他  <code>application-env.template.yml</code></p>
<div class="highlight-container" data-rel="Yml"><figure class="iseeu highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">### idea</span></span><br><span class="line"><span class="string">/.idea</span></span><br><span class="line"><span class="string">*.iml</span></span><br><span class="line"><span class="string">*.ipr</span></span><br><span class="line"><span class="string">/out</span></span><br><span class="line"></span><br><span class="line"><span class="comment">### gradle</span></span><br><span class="line"><span class="string">/.gradle</span></span><br><span class="line"><span class="string">/build</span></span><br><span class="line"></span><br><span class="line"><span class="comment">### Environment Configuration</span></span><br><span class="line"><span class="string">application-*.yml</span></span><br><span class="line"><span class="type">!application</span><span class="string">-env.template.yml</span></span><br></pre></td></tr></table></figure></div>
<h3 id="静态检查"><a class="markdownIt-Anchor" href="#静态检查">#</a> 静态检查</h3>
<p>增加 checkStyle 插件</p>
<div class="highlight-container" data-rel="Kotlin"><figure class="iseeu highlight kotlin"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">plugins &#123;</span><br><span class="line">    java</span><br><span class="line">    id(<span class="string">&quot;org.springframework.boot&quot;</span>) version <span class="string">&quot;2.6.4&quot;</span></span><br><span class="line">    checkstyle</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></div>
<p>添加配置</p>
<div class="highlight-container" data-rel="Kotlin"><figure class="iseeu highlight kotlin"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">checkstyle &#123;</span><br><span class="line">    maxWarnings = <span class="number">0</span> <span class="comment">//最大警告数,即项目里不允许有不符合checkStyle规范的代码存在</span></span><br><span class="line">    toolVersion = <span class="string">&quot;10.0&quot;</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></div>
<p>在项目的根目录中新增 checkStyle 配置文件</p>
<p><img  
                     lazyload
                     src="/images/loading.svg"
                     data-src="http://tuchuang.wenhe9.cn/img/202306181921279.png"
                      alt="image-20230618192117216"
                ></p>
<div class="highlight-container" data-rel="Plaintext"><figure class="iseeu highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br><span class="line">214</span><br><span class="line">215</span><br><span class="line">216</span><br><span class="line">217</span><br><span class="line">218</span><br><span class="line">219</span><br><span class="line">220</span><br><span class="line">221</span><br><span class="line">222</span><br><span class="line">223</span><br><span class="line">224</span><br><span class="line">225</span><br><span class="line">226</span><br><span class="line">227</span><br><span class="line">228</span><br><span class="line">229</span><br><span class="line">230</span><br><span class="line">231</span><br><span class="line">232</span><br><span class="line">233</span><br><span class="line">234</span><br><span class="line">235</span><br><span class="line">236</span><br><span class="line">237</span><br><span class="line">238</span><br></pre></td><td class="code"><pre><span class="line">&lt;?xml version=&quot;1.0&quot;?&gt;</span><br><span class="line">&lt;!DOCTYPE module PUBLIC</span><br><span class="line">        &quot;-//Checkstyle//DTD Checkstyle Configuration 1.3//EN&quot;</span><br><span class="line">        &quot;https://checkstyle.org/dtds/configuration_1_3.dtd&quot;&gt;</span><br><span class="line">&lt;module name=&quot;Checker&quot;&gt;</span><br><span class="line">    &lt;property name=&quot;charset&quot; value=&quot;UTF-8&quot;/&gt;</span><br><span class="line">    &lt;property name=&quot;severity&quot; value=&quot;warning&quot;/&gt;</span><br><span class="line">    &lt;property name=&quot;fileExtensions&quot; value=&quot;java, properties, xml&quot;/&gt;</span><br><span class="line">    &lt;module name=&quot;BeforeExecutionExclusionFileFilter&quot;&gt;</span><br><span class="line">        &lt;property name=&quot;fileNamePattern&quot; value=&quot;module\-info\.java$&quot;/&gt;</span><br><span class="line">    &lt;/module&gt;</span><br><span class="line">    &lt;module name=&quot;FileTabCharacter&quot;&gt;</span><br><span class="line">        &lt;property name=&quot;eachLine&quot; value=&quot;true&quot;/&gt;</span><br><span class="line">    &lt;/module&gt;</span><br><span class="line">    &lt;module name=&quot;LineLength&quot;&gt;</span><br><span class="line">        &lt;property name=&quot;fileExtensions&quot; value=&quot;java&quot;/&gt;</span><br><span class="line">        &lt;property name=&quot;max&quot; value=&quot;160&quot;/&gt;</span><br><span class="line">        &lt;property name=&quot;ignorePattern&quot; value=&quot;^package.*|^import.*|a href|href|http://|https://|ftp://&quot;/&gt;</span><br><span class="line">    &lt;/module&gt;</span><br><span class="line">    &lt;module name=&quot;TreeWalker&quot;&gt;</span><br><span class="line">        &lt;module name=&quot;UnusedImports&quot;/&gt;</span><br><span class="line">        &lt;module name=&quot;OuterTypeFilename&quot;/&gt;</span><br><span class="line">        &lt;module name=&quot;IllegalTokenText&quot;&gt;</span><br><span class="line">            &lt;property name=&quot;tokens&quot; value=&quot;STRING_LITERAL, CHAR_LITERAL&quot;/&gt;</span><br><span class="line">            &lt;property name=&quot;format&quot; value=&quot;\\u00(09|0(a|A)|0(c|C)|0(d|D)|22|27|5(C|c))|\\(0(10|11|12|14|15|42|47)|134)&quot;/&gt;</span><br><span class="line">            &lt;property name=&quot;message&quot; value=&quot;Consider using special escape sequence instead of octal value or Unicode escaped value.&quot;/&gt;</span><br><span class="line">        &lt;/module&gt;</span><br><span class="line">        &lt;module name=&quot;AvoidEscapedUnicodeCharacters&quot;&gt;</span><br><span class="line">            &lt;property name=&quot;allowEscapesForControlCharacters&quot; value=&quot;true&quot;/&gt;</span><br><span class="line">            &lt;property name=&quot;allowByTailComment&quot; value=&quot;true&quot;/&gt;</span><br><span class="line">            &lt;property name=&quot;allowNonPrintableEscapes&quot; value=&quot;true&quot;/&gt;</span><br><span class="line">        &lt;/module&gt;</span><br><span class="line">        &lt;module name=&quot;AvoidStarImport&quot;/&gt;</span><br><span class="line">        &lt;module name=&quot;OneTopLevelClass&quot;/&gt;</span><br><span class="line">        &lt;module name=&quot;NoLineWrap&quot;&gt;</span><br><span class="line">            &lt;property name=&quot;tokens&quot; value=&quot;PACKAGE_DEF, IMPORT, STATIC_IMPORT&quot;/&gt;</span><br><span class="line">        &lt;/module&gt;</span><br><span class="line">        &lt;module name=&quot;EmptyBlock&quot;&gt;</span><br><span class="line">            &lt;property name=&quot;option&quot; value=&quot;TEXT&quot;/&gt;</span><br><span class="line">            &lt;property name=&quot;tokens&quot; value=&quot;LITERAL_TRY, LITERAL_FINALLY, LITERAL_IF, LITERAL_ELSE, LITERAL_SWITCH&quot;/&gt;</span><br><span class="line">        &lt;/module&gt;</span><br><span class="line">        &lt;module name=&quot;LeftCurly&quot;&gt;</span><br><span class="line">            &lt;property name=&quot;tokens&quot; value=&quot;ANNOTATION_DEF, CLASS_DEF, CTOR_DEF, ENUM_CONSTANT_DEF, ENUM_DEF, INTERFACE_DEF, LAMBDA, LITERAL_CASE, LITERAL_CATCH,</span><br><span class="line">             LITERAL_DEFAULT, LITERAL_DO, LITERAL_ELSE, LITERAL_FINALLY, LITERAL_FOR, LITERAL_IF, LITERAL_SWITCH, LITERAL_SYNCHRONIZED, LITERAL_TRY,</span><br><span class="line">             LITERAL_WHILE, METHOD_DEF, OBJBLOCK, STATIC_INIT, RECORD_DEF, COMPACT_CTOR_DEF&quot;/&gt;</span><br><span class="line">        &lt;/module&gt;</span><br><span class="line">        &lt;module name=&quot;RightCurly&quot;&gt;</span><br><span class="line">            &lt;property name=&quot;id&quot; value=&quot;RightCurlySame&quot;/&gt;</span><br><span class="line">            &lt;property name=&quot;tokens&quot; value=&quot;LITERAL_TRY, LITERAL_CATCH, LITERAL_FINALLY, LITERAL_IF, LITERAL_ELSE, LITERAL_DO&quot;/&gt;</span><br><span class="line">        &lt;/module&gt;</span><br><span class="line">        &lt;module name=&quot;RightCurly&quot;&gt;</span><br><span class="line">            &lt;property name=&quot;id&quot; value=&quot;RightCurlyAlone&quot;/&gt;</span><br><span class="line">            &lt;property name=&quot;option&quot; value=&quot;alone&quot;/&gt;</span><br><span class="line">            &lt;property name=&quot;tokens&quot;</span><br><span class="line">                      value=&quot;CLASS_DEF, METHOD_DEF, CTOR_DEF, LITERAL_FOR, LITERAL_WHILE, STATIC_INIT, INSTANCE_INIT, ANNOTATION_DEF, ENUM_DEF, INTERFACE_DEF, RECORD_DEF, COMPACT_CTOR_DEF&quot;/&gt;</span><br><span class="line">        &lt;/module&gt;</span><br><span class="line">        &lt;module name=&quot;SuppressionXpathSingleFilter&quot;&gt;</span><br><span class="line">            &lt;property name=&quot;id&quot; value=&quot;RightCurlyAlone&quot;/&gt;</span><br><span class="line">            &lt;property name=&quot;query&quot; value=&quot;//RCURLY[parent::SLIST[count(./*)=1] or preceding-sibling::*[last()][self::LCURLY]]&quot;/&gt;</span><br><span class="line">        &lt;/module&gt;</span><br><span class="line">        &lt;module name=&quot;WhitespaceAfter&quot;&gt;</span><br><span class="line">            &lt;property name=&quot;tokens&quot; value=&quot;COMMA, SEMI, TYPECAST, LITERAL_IF, LITERAL_ELSE, LITERAL_WHILE, LITERAL_DO, LITERAL_FOR, DO_WHILE&quot;/&gt;</span><br><span class="line">        &lt;/module&gt;</span><br><span class="line">        &lt;module name=&quot;WhitespaceAround&quot;&gt;</span><br><span class="line">            &lt;property name=&quot;allowEmptyConstructors&quot; value=&quot;true&quot;/&gt;</span><br><span class="line">            &lt;property name=&quot;allowEmptyLambdas&quot; value=&quot;true&quot;/&gt;</span><br><span class="line">            &lt;property name=&quot;allowEmptyMethods&quot; value=&quot;true&quot;/&gt;</span><br><span class="line">            &lt;property name=&quot;allowEmptyTypes&quot; value=&quot;true&quot;/&gt;</span><br><span class="line">            &lt;property name=&quot;allowEmptyLoops&quot; value=&quot;true&quot;/&gt;</span><br><span class="line">            &lt;property name=&quot;ignoreEnhancedForColon&quot; value=&quot;false&quot;/&gt;</span><br><span class="line">            &lt;property name=&quot;tokens&quot; value=&quot;ASSIGN, BAND, BAND_ASSIGN, BOR, BOR_ASSIGN, BSR, BSR_ASSIGN, BXOR, BXOR_ASSIGN, COLON, DIV, DIV_ASSIGN, DO_WHILE,</span><br><span class="line">            EQUAL, GE, GT, LAMBDA, LAND, LCURLY, LE, LITERAL_CATCH, LITERAL_DO, LITERAL_ELSE, LITERAL_FINALLY, LITERAL_FOR, LITERAL_IF, LITERAL_RETURN,</span><br><span class="line">            LITERAL_SWITCH, LITERAL_SYNCHRONIZED, LITERAL_TRY, LITERAL_WHILE, LOR, LT, MINUS, MINUS_ASSIGN, MOD, MOD_ASSIGN, NOT_EQUAL, PLUS, PLUS_ASSIGN,</span><br><span class="line">            QUESTION, RCURLY, SL, SLIST, SL_ASSIGN, SR, SR_ASSIGN, STAR, STAR_ASSIGN, LITERAL_ASSERT, TYPE_EXTENSION_AND&quot;/&gt;</span><br><span class="line">            &lt;message key=&quot;ws.notFollowed&quot;</span><br><span class="line">                     value=&quot;WhitespaceAround: &#x27;&#x27;&#123;0&#125;&#x27;&#x27; is not followed by whitespace. Empty blocks may only be represented as &#x27;&#123;&#125;&#x27; when not part of a multi-block statement (4.1.3)&quot;/&gt;</span><br><span class="line">            &lt;message key=&quot;ws.notPreceded&quot; value=&quot;WhitespaceAround: &#x27;&#x27;&#123;0&#125;&#x27;&#x27; is not preceded with whitespace.&quot;/&gt;</span><br><span class="line">        &lt;/module&gt;</span><br><span class="line">        &lt;module name=&quot;OneStatementPerLine&quot;/&gt;</span><br><span class="line">        &lt;module name=&quot;MultipleVariableDeclarations&quot;/&gt;</span><br><span class="line">        &lt;module name=&quot;ArrayTypeStyle&quot;/&gt;</span><br><span class="line">        &lt;module name=&quot;MissingSwitchDefault&quot;/&gt;</span><br><span class="line">        &lt;module name=&quot;FallThrough&quot;/&gt;</span><br><span class="line">        &lt;module name=&quot;UpperEll&quot;/&gt;</span><br><span class="line">        &lt;module name=&quot;ModifierOrder&quot;/&gt;</span><br><span class="line">        &lt;module name=&quot;EmptyLineSeparator&quot;&gt;</span><br><span class="line">            &lt;property name=&quot;tokens&quot; value=&quot;PACKAGE_DEF, IMPORT, STATIC_IMPORT, CLASS_DEF, INTERFACE_DEF, ENUM_DEF, STATIC_INIT, INSTANCE_INIT, METHOD_DEF, CTOR_DEF, VARIABLE_DEF, RECORD_DEF, COMPACT_CTOR_DEF&quot;/&gt;</span><br><span class="line">            &lt;property name=&quot;allowNoEmptyLineBetweenFields&quot; value=&quot;true&quot;/&gt;</span><br><span class="line">            &lt;property name=&quot;allowMultipleEmptyLinesInsideClassMembers&quot; value=&quot;false&quot;/&gt;</span><br><span class="line">            &lt;property name=&quot;allowMultipleEmptyLines&quot; value=&quot;false&quot;/&gt;</span><br><span class="line">        &lt;/module&gt;</span><br><span class="line">        &lt;module name=&quot;SeparatorWrap&quot;&gt;</span><br><span class="line">            &lt;property name=&quot;id&quot; value=&quot;SeparatorWrapDot&quot;/&gt;</span><br><span class="line">            &lt;property name=&quot;tokens&quot; value=&quot;DOT&quot;/&gt;</span><br><span class="line">            &lt;property name=&quot;option&quot; value=&quot;nl&quot;/&gt;</span><br><span class="line">        &lt;/module&gt;</span><br><span class="line">        &lt;module name=&quot;SeparatorWrap&quot;&gt;</span><br><span class="line">            &lt;property name=&quot;id&quot; value=&quot;SeparatorWrapComma&quot;/&gt;</span><br><span class="line">            &lt;property name=&quot;tokens&quot; value=&quot;COMMA&quot;/&gt;</span><br><span class="line">            &lt;property name=&quot;option&quot; value=&quot;EOL&quot;/&gt;</span><br><span class="line">        &lt;/module&gt;</span><br><span class="line">        &lt;module name=&quot;SeparatorWrap&quot;&gt;</span><br><span class="line">            &lt;property name=&quot;id&quot; value=&quot;SeparatorWrapEllipsis&quot;/&gt;</span><br><span class="line">            &lt;property name=&quot;tokens&quot; value=&quot;ELLIPSIS&quot;/&gt;</span><br><span class="line">            &lt;property name=&quot;option&quot; value=&quot;EOL&quot;/&gt;</span><br><span class="line">        &lt;/module&gt;</span><br><span class="line">        &lt;module name=&quot;SeparatorWrap&quot;&gt;</span><br><span class="line">            &lt;property name=&quot;id&quot; value=&quot;SeparatorWrapArrayDeclarator&quot;/&gt;</span><br><span class="line">            &lt;property name=&quot;tokens&quot; value=&quot;ARRAY_DECLARATOR&quot;/&gt;</span><br><span class="line">            &lt;property name=&quot;option&quot; value=&quot;EOL&quot;/&gt;</span><br><span class="line">        &lt;/module&gt;</span><br><span class="line">        &lt;module name=&quot;SeparatorWrap&quot;&gt;</span><br><span class="line">            &lt;property name=&quot;id&quot; value=&quot;SeparatorWrapMethodRef&quot;/&gt;</span><br><span class="line">            &lt;property name=&quot;tokens&quot; value=&quot;METHOD_REF&quot;/&gt;</span><br><span class="line">            &lt;property name=&quot;option&quot; value=&quot;nl&quot;/&gt;</span><br><span class="line">        &lt;/module&gt;</span><br><span class="line">        &lt;module name=&quot;PackageName&quot;&gt;</span><br><span class="line">            &lt;property name=&quot;format&quot; value=&quot;^[a-z]+(\.[a-z][a-z0-9]*)*$&quot;/&gt;</span><br><span class="line">            &lt;message key=&quot;name.invalidPattern&quot; value=&quot;Package name &#x27;&#x27;&#123;0&#125;&#x27;&#x27; must match pattern &#x27;&#x27;&#123;1&#125;&#x27;&#x27;.&quot;/&gt;</span><br><span class="line">        &lt;/module&gt;</span><br><span class="line">        &lt;module name=&quot;TypeName&quot;&gt;</span><br><span class="line">            &lt;property name=&quot;tokens&quot; value=&quot;CLASS_DEF, INTERFACE_DEF, ENUM_DEF, ANNOTATION_DEF, RECORD_DEF&quot;/&gt;</span><br><span class="line">            &lt;message key=&quot;name.invalidPattern&quot; value=&quot;Type name &#x27;&#x27;&#123;0&#125;&#x27;&#x27; must match pattern &#x27;&#x27;&#123;1&#125;&#x27;&#x27;.&quot;/&gt;</span><br><span class="line">        &lt;/module&gt;</span><br><span class="line">        &lt;module name=&quot;MemberName&quot;&gt;</span><br><span class="line">            &lt;property name=&quot;format&quot; value=&quot;^[a-z][a-z0-9][a-zA-Z0-9]*$&quot;/&gt;</span><br><span class="line">            &lt;message key=&quot;name.invalidPattern&quot; value=&quot;Member name &#x27;&#x27;&#123;0&#125;&#x27;&#x27; must match pattern &#x27;&#x27;&#123;1&#125;&#x27;&#x27;.&quot;/&gt;</span><br><span class="line">        &lt;/module&gt;</span><br><span class="line">        &lt;module name=&quot;ParameterName&quot;&gt;</span><br><span class="line">            &lt;property name=&quot;format&quot; value=&quot;^[a-z]([a-z0-9][a-zA-Z0-9]*)?$&quot;/&gt;</span><br><span class="line">            &lt;message key=&quot;name.invalidPattern&quot; value=&quot;Parameter name &#x27;&#x27;&#123;0&#125;&#x27;&#x27; must match pattern &#x27;&#x27;&#123;1&#125;&#x27;&#x27;.&quot;/&gt;</span><br><span class="line">        &lt;/module&gt;</span><br><span class="line">        &lt;module name=&quot;LambdaParameterName&quot;&gt;</span><br><span class="line">            &lt;property name=&quot;format&quot; value=&quot;^[a-z]([a-z0-9][a-zA-Z0-9]*)?$&quot;/&gt;</span><br><span class="line">            &lt;message key=&quot;name.invalidPattern&quot; value=&quot;Lambda parameter name &#x27;&#x27;&#123;0&#125;&#x27;&#x27; must match pattern &#x27;&#x27;&#123;1&#125;&#x27;&#x27;.&quot;/&gt;</span><br><span class="line">        &lt;/module&gt;</span><br><span class="line">        &lt;module name=&quot;CatchParameterName&quot;&gt;</span><br><span class="line">            &lt;property name=&quot;format&quot; value=&quot;^[a-z]([a-z0-9][a-zA-Z0-9]*)?$&quot;/&gt;</span><br><span class="line">            &lt;message key=&quot;name.invalidPattern&quot; value=&quot;Catch parameter name &#x27;&#x27;&#123;0&#125;&#x27;&#x27; must match pattern &#x27;&#x27;&#123;1&#125;&#x27;&#x27;.&quot;/&gt;</span><br><span class="line">        &lt;/module&gt;</span><br><span class="line">        &lt;module name=&quot;LocalVariableName&quot;&gt;</span><br><span class="line">            &lt;property name=&quot;format&quot; value=&quot;^[a-z]([a-z0-9][a-zA-Z0-9]*)?$&quot;/&gt;</span><br><span class="line">            &lt;message key=&quot;name.invalidPattern&quot; value=&quot;Local variable name &#x27;&#x27;&#123;0&#125;&#x27;&#x27; must match pattern &#x27;&#x27;&#123;1&#125;&#x27;&#x27;.&quot;/&gt;</span><br><span class="line">        &lt;/module&gt;</span><br><span class="line">        &lt;module name=&quot;PatternVariableName&quot;&gt;</span><br><span class="line">            &lt;property name=&quot;format&quot; value=&quot;^[a-z]([a-z0-9][a-zA-Z0-9]*)?$&quot;/&gt;</span><br><span class="line">            &lt;message key=&quot;name.invalidPattern&quot; value=&quot;Pattern variable name &#x27;&#x27;&#123;0&#125;&#x27;&#x27; must match pattern &#x27;&#x27;&#123;1&#125;&#x27;&#x27;.&quot;/&gt;</span><br><span class="line">        &lt;/module&gt;</span><br><span class="line">        &lt;module name=&quot;ClassTypeParameterName&quot;&gt;</span><br><span class="line">            &lt;property name=&quot;format&quot; value=&quot;(^[A-Z][0-9]?)$|([A-Z][a-zA-Z0-9]*[T]$)&quot;/&gt;</span><br><span class="line">            &lt;message key=&quot;name.invalidPattern&quot; value=&quot;Class type name &#x27;&#x27;&#123;0&#125;&#x27;&#x27; must match pattern &#x27;&#x27;&#123;1&#125;&#x27;&#x27;.&quot;/&gt;</span><br><span class="line">        &lt;/module&gt;</span><br><span class="line">        &lt;module name=&quot;RecordTypeParameterName&quot;&gt;</span><br><span class="line">            &lt;property name=&quot;format&quot; value=&quot;(^[A-Z][0-9]?)$|([A-Z][a-zA-Z0-9]*[T]$)&quot;/&gt;</span><br><span class="line">            &lt;message key=&quot;name.invalidPattern&quot; value=&quot;Record type name &#x27;&#x27;&#123;0&#125;&#x27;&#x27; must match pattern &#x27;&#x27;&#123;1&#125;&#x27;&#x27;.&quot;/&gt;</span><br><span class="line">        &lt;/module&gt;</span><br><span class="line">        &lt;module name=&quot;MethodTypeParameterName&quot;&gt;</span><br><span class="line">            &lt;property name=&quot;format&quot; value=&quot;(^[A-Z][0-9]?)$|([A-Z][a-zA-Z0-9]*[T]$)&quot;/&gt;</span><br><span class="line">            &lt;message key=&quot;name.invalidPattern&quot; value=&quot;Method type name &#x27;&#x27;&#123;0&#125;&#x27;&#x27; must match pattern &#x27;&#x27;&#123;1&#125;&#x27;&#x27;.&quot;/&gt;</span><br><span class="line">        &lt;/module&gt;</span><br><span class="line">        &lt;module name=&quot;NoFinalizer&quot;/&gt;</span><br><span class="line">        &lt;module name=&quot;GenericWhitespace&quot;&gt;</span><br><span class="line">            &lt;message key=&quot;ws.followed&quot; value=&quot;GenericWhitespace &#x27;&#x27;&#123;0&#125;&#x27;&#x27; is followed by whitespace.&quot;/&gt;</span><br><span class="line">            &lt;message key=&quot;ws.preceded&quot; value=&quot;GenericWhitespace &#x27;&#x27;&#123;0&#125;&#x27;&#x27; is preceded with whitespace.&quot;/&gt;</span><br><span class="line">            &lt;message key=&quot;ws.illegalFollow&quot; value=&quot;GenericWhitespace &#x27;&#x27;&#123;0&#125;&#x27;&#x27; should followed by whitespace.&quot;/&gt;</span><br><span class="line">            &lt;message key=&quot;ws.notPreceded&quot; value=&quot;GenericWhitespace &#x27;&#x27;&#123;0&#125;&#x27;&#x27; is not preceded with whitespace.&quot;/&gt;</span><br><span class="line">        &lt;/module&gt;</span><br><span class="line">        &lt;module name=&quot;Indentation&quot;&gt;</span><br><span class="line">            &lt;property name=&quot;basicOffset&quot; value=&quot;4&quot;/&gt;</span><br><span class="line">            &lt;property name=&quot;braceAdjustment&quot; value=&quot;4&quot;/&gt;</span><br><span class="line">            &lt;property name=&quot;caseIndent&quot; value=&quot;4&quot;/&gt;</span><br><span class="line">            &lt;property name=&quot;throwsIndent&quot; value=&quot;4&quot;/&gt;</span><br><span class="line">            &lt;property name=&quot;lineWrappingIndentation&quot; value=&quot;4&quot;/&gt;</span><br><span class="line">            &lt;property name=&quot;arrayInitIndent&quot; value=&quot;4&quot;/&gt;</span><br><span class="line">        &lt;/module&gt;</span><br><span class="line">        &lt;module name=&quot;AbbreviationAsWordInName&quot;&gt;</span><br><span class="line">            &lt;property name=&quot;ignoreFinal&quot; value=&quot;false&quot;/&gt;</span><br><span class="line">            &lt;property name=&quot;allowedAbbreviationLength&quot; value=&quot;0&quot;/&gt;</span><br><span class="line">            &lt;property name=&quot;tokens&quot;</span><br><span class="line">                      value=&quot;CLASS_DEF, INTERFACE_DEF, ENUM_DEF, ANNOTATION_DEF, ANNOTATION_FIELD_DEF, PARAMETER_DEF, VARIABLE_DEF, METHOD_DEF, PATTERN_VARIABLE_DEF, RECORD_DEF, RECORD_COMPONENT_DEF&quot;/&gt;</span><br><span class="line">        &lt;/module&gt;</span><br><span class="line">        &lt;module name=&quot;OverloadMethodsDeclarationOrder&quot;/&gt;</span><br><span class="line">        &lt;module name=&quot;VariableDeclarationUsageDistance&quot;/&gt;</span><br><span class="line">        &lt;module name=&quot;MethodParamPad&quot;&gt;</span><br><span class="line">            &lt;property name=&quot;tokens&quot; value=&quot;CTOR_DEF, LITERAL_NEW, METHOD_CALL, METHOD_DEF, SUPER_CTOR_CALL, ENUM_CONSTANT_DEF, RECORD_DEF&quot;/&gt;</span><br><span class="line">        &lt;/module&gt;</span><br><span class="line">        &lt;module name=&quot;NoWhitespaceBefore&quot;&gt;</span><br><span class="line">            &lt;property name=&quot;tokens&quot; value=&quot;COMMA, SEMI, POST_INC, POST_DEC, DOT, LABELED_STAT, METHOD_REF&quot;/&gt;</span><br><span class="line">            &lt;property name=&quot;allowLineBreaks&quot; value=&quot;true&quot;/&gt;</span><br><span class="line">        &lt;/module&gt;</span><br><span class="line">        &lt;module name=&quot;ParenPad&quot;&gt;</span><br><span class="line">            &lt;property name=&quot;tokens&quot;</span><br><span class="line">                      value=&quot;ANNOTATION, ANNOTATION_FIELD_DEF, CTOR_CALL, CTOR_DEF, DOT, ENUM_CONSTANT_DEF, EXPR, LITERAL_CATCH, LITERAL_DO, LITERAL_FOR, LITERAL_IF, LITERAL_NEW, LITERAL_SWITCH, LITERAL_SYNCHRONIZED, LITERAL_WHILE, METHOD_CALL, METHOD_DEF, QUESTION, RESOURCE_SPECIFICATION, SUPER_CTOR_CALL, LAMBDA, RECORD_DEF&quot;/&gt;</span><br><span class="line">        &lt;/module&gt;</span><br><span class="line">        &lt;module name=&quot;OperatorWrap&quot;&gt;</span><br><span class="line">            &lt;property name=&quot;option&quot; value=&quot;NL&quot;/&gt;</span><br><span class="line">            &lt;property name=&quot;tokens&quot;</span><br><span class="line">                      value=&quot;BAND, BOR, BSR, BXOR, DIV, EQUAL, GE, GT, LAND, LE, LITERAL_INSTANCEOF, LOR, LT, MINUS, MOD, NOT_EQUAL, PLUS, QUESTION, SL, SR, STAR, METHOD_REF, TYPE_EXTENSION_AND &quot;/&gt;</span><br><span class="line">        &lt;/module&gt;</span><br><span class="line">        &lt;module name=&quot;AnnotationLocation&quot;&gt;</span><br><span class="line">            &lt;property name=&quot;id&quot; value=&quot;AnnotationLocationMostCases&quot;/&gt;</span><br><span class="line">            &lt;property name=&quot;tokens&quot; value=&quot;CLASS_DEF, INTERFACE_DEF, ENUM_DEF, METHOD_DEF, CTOR_DEF, RECORD_DEF, COMPACT_CTOR_DEF&quot;/&gt;</span><br><span class="line">        &lt;/module&gt;</span><br><span class="line">        &lt;module name=&quot;AnnotationLocation&quot;&gt;</span><br><span class="line">            &lt;property name=&quot;id&quot; value=&quot;AnnotationLocationVariables&quot;/&gt;</span><br><span class="line">            &lt;property name=&quot;tokens&quot; value=&quot;VARIABLE_DEF&quot;/&gt;</span><br><span class="line">            &lt;property name=&quot;allowSamelineMultipleAnnotations&quot; value=&quot;true&quot;/&gt;</span><br><span class="line">        &lt;/module&gt;</span><br><span class="line">        &lt;module name=&quot;NonEmptyAtclauseDescription&quot;/&gt;</span><br><span class="line">&lt;!--        &lt;module name=&quot;InvalidJavadocPosition&quot;/&gt;--&gt;</span><br><span class="line">&lt;!--        &lt;module name=&quot;JavadocTagContinuationIndentation&quot;/&gt;--&gt;</span><br><span class="line">&lt;!--        &lt;module name=&quot;SummaryJavadoc&quot;&gt;--&gt;</span><br><span class="line">&lt;!--            &lt;property name=&quot;forbiddenSummaryFragments&quot; value=&quot;^@return the *|^This method returns |^A [&#123;]@code [a-zA-Z0-9]+[&#125;]( is a )&quot;/&gt;--&gt;</span><br><span class="line">&lt;!--        &lt;/module&gt;--&gt;</span><br><span class="line">&lt;!--        &lt;module name=&quot;JavadocParagraph&quot;/&gt;--&gt;</span><br><span class="line">        &lt;module name=&quot;RequireEmptyLineBeforeBlockTagGroup&quot;/&gt;</span><br><span class="line">        &lt;module name=&quot;AtclauseOrder&quot;&gt;</span><br><span class="line">            &lt;property name=&quot;tagOrder&quot; value=&quot;@param, @return, @throws, @deprecated&quot;/&gt;</span><br><span class="line">            &lt;property name=&quot;target&quot; value=&quot;CLASS_DEF, INTERFACE_DEF, ENUM_DEF, METHOD_DEF, CTOR_DEF, VARIABLE_DEF&quot;/&gt;</span><br><span class="line">        &lt;/module&gt;</span><br><span class="line">        &lt;module name=&quot;MethodName&quot;&gt;</span><br><span class="line">            &lt;property name=&quot;format&quot; value=&quot;^[a-z][a-z0-9][a-zA-Z0-9_]*$&quot;/&gt;</span><br><span class="line">            &lt;message key=&quot;name.invalidPattern&quot; value=&quot;Method name &#x27;&#x27;&#123;0&#125;&#x27;&#x27; must match pattern &#x27;&#x27;&#123;1&#125;&#x27;&#x27;.&quot;/&gt;</span><br><span class="line">        &lt;/module&gt;</span><br><span class="line">&lt;!--        &lt;module name=&quot;SingleLineJavadoc&quot;/&gt;--&gt;</span><br><span class="line">        &lt;module name=&quot;EmptyCatchBlock&quot;&gt;</span><br><span class="line">            &lt;property name=&quot;exceptionVariableName&quot; value=&quot;expected&quot;/&gt;</span><br><span class="line">        &lt;/module&gt;</span><br><span class="line">        &lt;module name=&quot;CommentsIndentation&quot;&gt;</span><br><span class="line">            &lt;property name=&quot;tokens&quot; value=&quot;SINGLE_LINE_COMMENT, BLOCK_COMMENT_BEGIN&quot;/&gt;</span><br><span class="line">        &lt;/module&gt;</span><br><span class="line">        &lt;module name=&quot;SuppressionXpathFilter&quot;&gt;</span><br><span class="line">            &lt;property name=&quot;file&quot; value=&quot;$&#123;org.checkstyle.google.suppressionxpathfilter.config&#125;&quot; default=&quot;checkstyle-xpath-suppressions.xml&quot;/&gt;</span><br><span class="line">            &lt;property name=&quot;optional&quot; value=&quot;true&quot;/&gt;</span><br><span class="line">        &lt;/module&gt;</span><br><span class="line">    &lt;/module&gt;</span><br><span class="line">&lt;/module&gt;</span><br><span class="line"></span><br></pre></td></tr></table></figure></div>
<p>执行 <code>./gradlew check</code>  会去执行除了 测试方法的 task 方法外，还会去执行类似 checkStyle 这样的一些检查插件，在 check 的时候就会对静态样式进行检查</p>
<h3 id="业务开发"><a class="markdownIt-Anchor" href="#业务开发">#</a> 业务开发</h3>
<h4 id="record-纪录类"><a class="markdownIt-Anchor" href="#record-纪录类">#</a> record 纪录类</h4>
<p>对于纯 pojo 而言，在 Java16 之后可以使用 record 记录类来创建，类似于 Kotlin 的 data class 类型，使用时会自动生成他的所有字段的 get 方法，并且这些字段都是 immutable 的，即无法修改的</p>
<div class="highlight-container" data-rel="Java"><figure class="iseeu highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@description</span>: 创建问题命令</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@author</span>: DuJinliang</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@create</span>: 2023/6/18</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">record</span> <span class="title class_">CreateQuestionCmd</span><span class="params">(</span></span><br><span class="line"><span class="params">        String questionerId,</span></span><br><span class="line"><span class="params">        String title,</span></span><br><span class="line"><span class="params">        String detail</span></span><br><span class="line"><span class="params">)</span> &#123;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></div>
<h3 id="spring-注入"><a class="markdownIt-Anchor" href="#spring-注入">#</a> spring 注入</h3>
<p>如果使用字段注入的话，使用 <code>@Autowired</code>  对 Spring 框架的依赖时比较重的，如果没有依赖 Spring 框架很难去初始化这样一个对象，并且尝试对这样的 bean 进行测试的话，甚至都无法很好的构造出来，因为 Spring 可能还要通过反射去注入的，那么比较的推荐的就是通过构造器的方式注入，为了防止我们创建对应的构造器这件事，比较推荐的是将这种字段全部都声明为 final 类型</p>
<ul>
<li>使用 final 的优点，没有办法在业务代码中去替换调实现</li>
<li>强制要求把参数放到构造器上，这样的话帮我们不要忘记写这个方法，有了构造方法 spring 才能通过构造器的方式注入 bean</li>
</ul>
<div class="highlight-container" data-rel="Java"><figure class="iseeu highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Transactional</span></span><br><span class="line"><span class="meta">@Service(&quot;questionCommandServiceImpl&quot;)</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">QuestionCommandServiceImpl</span> <span class="keyword">implements</span> <span class="title class_">QuestionCommandService</span> &#123;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">final</span> QuestionRepository questionRepository;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">public</span> <span class="title function_">QuestionCommandServiceImpl</span><span class="params">(QuestionRepository questionRepository)</span> &#123;</span><br><span class="line">        <span class="built_in">this</span>.questionRepository = questionRepository;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="keyword">public</span> QuestionCreateResult <span class="title function_">createQuestion</span><span class="params">(CreateQuestionCmd cmd)</span> &#123;</span><br><span class="line">        <span class="type">var</span> <span class="variable">question</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">Question</span>(cmd.questionerId(), cmd.title(), cmd.detail());</span><br><span class="line">        questionRepository.save(question);</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">new</span> <span class="title class_">QuestionCreateResult</span>(question.getId());</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></div>
<h3 id="事务边界"><a class="markdownIt-Anchor" href="#事务边界">#</a> 事务边界</h3>
<p>添加事务边界，应用服务的每一个方法其实就可以理解为我们的一个最小的事务单元，在类上加一个  <code>@Transactional</code>  注解，这样每当我们调用一个方法的时候，他就会开启一个事务</p>
<ul>
<li>spring data jpa 有一个默认的参数
<ul>
<li>open-in-view : true</li>
<li>他的意思是指，jpa 会在每个 web 请求进来的时候就会开启一个数据库的连接会话，开启一个事务，直到请求结束，session 关闭，事务才会关闭提交，</li>
<li>如果这个配置开启的话，我们内容创建的手动声明的事务是被覆盖的</li>
</ul>
</li>
</ul>
<h3 id="测试-2"><a class="markdownIt-Anchor" href="#测试-2">#</a> 测试</h3>
<p>使用 MockMvc 来帮我们编写这个测试，需要添加一个注解  <code>@WebMvcTest</code></p>
<p>这里使用到了 Java17 的多行字符串的特性 “”&quot; “”“”</p>
<p>在这个测试中，我们只启动了 WebMvc 这一层的 bean，他还需要依赖我们的应用服务，在测试的时候，我们不希望他把所有东西都启动起来，所以我们需要把应用服务 mock 掉， 所以只需要将他声明成一个  <code>@MockBean</code>  即可，这样 spring 就直接可以把他变成一个 mock 的状态了，之后我们就可以使用 given 的方式给他指定返回值</p>
<p>但是使用这个字符串模板的话，可能会有一个缺点，如果对象比较复杂的话，会导致整个测试大段的代码都是定义了这个 json 对象，在测试的 resources 包下面去用文件去这些请求 body, 如果希望编写更多测试，也可以在编写更多 json 对象，也可以去继续完善这个测试，也可以写一些其他异常情况的测试也是一样的方式</p>
<p><img  
                     lazyload
                     src="/images/loading.svg"
                     data-src="http://tuchuang.wenhe9.cn/img/202306182028745.png"
                      alt="image-20230618202856687"
                ></p>
<div class="highlight-container" data-rel="Json"><figure class="iseeu highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="punctuation">&#123;</span></span><br><span class="line">  <span class="attr">&quot;questionerId&quot;</span><span class="punctuation">:</span> <span class="string">&quot;UID_00001&quot;</span><span class="punctuation">,</span></span><br><span class="line">  <span class="attr">&quot;title&quot;</span><span class="punctuation">:</span> <span class="string">&quot;A title for test&quot;</span><span class="punctuation">,</span></span><br><span class="line">  <span class="attr">&quot;detail&quot;</span><span class="punctuation">:</span> <span class="string">&quot;A detail for test&quot;</span></span><br><span class="line"><span class="punctuation">&#125;</span></span><br><span class="line"></span><br></pre></td></tr></table></figure></div>
<div class="highlight-container" data-rel="Java"><figure class="iseeu highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> cn.wenhe9.question.interfaces.question.face.rest;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> cn.wenhe9.question.domian.application.command.QuestionCommandService;</span><br><span class="line"><span class="keyword">import</span> cn.wenhe9.question.domian.application.result.QuestionCreateResult;</span><br><span class="line"><span class="keyword">import</span> org.junit.jupiter.api.Test;</span><br><span class="line"><span class="keyword">import</span> org.springframework.beans.factory.annotation.Autowired;</span><br><span class="line"><span class="keyword">import</span> org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;</span><br><span class="line"><span class="keyword">import</span> org.springframework.boot.test.mock.mockito.MockBean;</span><br><span class="line"><span class="keyword">import</span> org.springframework.core.io.ClassPathResource;</span><br><span class="line"><span class="keyword">import</span> org.springframework.http.MediaType;</span><br><span class="line"><span class="keyword">import</span> org.springframework.test.web.servlet.MockMvc;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> <span class="keyword">static</span> org.mockito.ArgumentMatchers.any;</span><br><span class="line"><span class="keyword">import</span> <span class="keyword">static</span> org.mockito.BDDMockito.given;</span><br><span class="line"><span class="keyword">import</span> <span class="keyword">static</span> org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;</span><br><span class="line"><span class="keyword">import</span> <span class="keyword">static</span> org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;</span><br><span class="line"><span class="keyword">import</span> <span class="keyword">static</span> org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@description</span>:</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@author</span>: DuJinliang</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@create</span>: 2023/6/18</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="meta">@WebMvcTest</span></span><br><span class="line"><span class="keyword">class</span> <span class="title class_">QuestionCommandRestControllerTest</span> &#123;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Autowired</span></span><br><span class="line">    <span class="keyword">private</span> MockMvc mockMvc;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@MockBean</span></span><br><span class="line">    <span class="keyword">private</span> QuestionCommandService questionCommandService;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Test</span></span><br><span class="line">    <span class="keyword">void</span> <span class="title function_">should_return_ok_when_create_question</span><span class="params">()</span> <span class="keyword">throws</span> Exception &#123;</span><br><span class="line">        <span class="type">var</span> <span class="variable">questionId</span> <span class="operator">=</span> <span class="string">&quot;1&quot;</span>;</span><br><span class="line">        given(questionCommandService.createQuestion(any())).willReturn(<span class="keyword">new</span> <span class="title class_">QuestionCreateResult</span>(questionId));</span><br><span class="line"></span><br><span class="line">        <span class="type">var</span> <span class="variable">requestBody</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">ClassPathResource</span>(<span class="string">&quot;request/question/create-question/200-ok.json&quot;</span>).getInputStream().readAllBytes();</span><br><span class="line"></span><br><span class="line">        mockMvc</span><br><span class="line">                .perform(</span><br><span class="line">                    post(<span class="string">&quot;/questions/&quot;</span>)</span><br><span class="line">                            .contentType(MediaType.APPLICATION_JSON)</span><br><span class="line">                            .content(requestBody)</span><br><span class="line">                )</span><br><span class="line">                .andExpect(status().isOk())</span><br><span class="line">                .andExpect(jsonPath(<span class="string">&quot;$.questionId&quot;</span>).value(questionId))</span><br><span class="line">        ;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure></div>

            </div>

            
                <div class="post-copyright-info">
                    <div class="article-copyright-info-container">
    <ul>
        <li><strong>标题:</strong> Java最佳实践</li>
        <li><strong>作者:</strong> meteor</li>
        <li><strong>创建于:</strong> 2023-06-18 20:41:10</li>
        
            <li>
                <strong>更新于:</strong> 2023-07-01 19:35:26
            </li>
        
        <li>
            <strong>链接:</strong> https://gitee.com/du-jinliang/2023/06/19/Java最佳实践/
        </li>
        <li>
            <strong>版权声明:</strong> 本文章采用 <a class="license" target="_blank" rel="noopener" href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh">CC BY-NC-SA 4.0</a> 进行许可。
        </li>
    </ul>
</div>

                </div>
            

            
                <ul class="post-tags-box">
                    
                        <li class="tag-item">
                            <a href="/tags/Java-%E6%9C%80%E4%BD%B3%E5%AE%9E%E8%B7%B5/">#Java 最佳实践</a>&nbsp;
                        </li>
                    
                </ul>
            

            

            
                <div class="article-nav">
                    
                        <div class="article-prev">
                            <a class="prev"
                            rel="prev"
                            href="/2023/08/06/HashSet%E5%B7%A5%E4%BD%9C%E5%8E%9F%E7%90%86/"
                            >
                                <span class="left arrow-icon flex-center">
                                    <i class="fa-solid fa-chevron-left"></i>
                                </span>
                                <span class="title flex-center">
                                    <span class="post-nav-title-item">HashSet工作原理</span>
                                    <span class="post-nav-item">上一篇</span>
                                </span>
                            </a>
                        </div>
                    
                    
                        <div class="article-next">
                            <a class="next"
                            rel="next"
                            href="/2023/06/06/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F/"
                            >
                                <span class="title flex-center">
                                    <span class="post-nav-title-item">设计模式</span>
                                    <span class="post-nav-item">下一篇</span>
                                </span>
                                <span class="right arrow-icon flex-center">
                                    <i class="fa-solid fa-chevron-right"></i>
                                </span>
                            </a>
                        </div>
                    
                </div>
            


            
                <div class="comment-container">
                    <div class="comments-container">
    <div id="comment-anchor"></div>
    <div class="comment-area-title">
        <i class="fa-solid fa-comments"></i>&nbsp;评论
    </div>
    

        
            
    <div id="gitalk-container"></div>
    <script data-pjax
            src="//cdn.jsdelivr.net/npm/gitalk/dist/gitalk.min.js"></script>
    <script data-pjax>

        function loadGitalk() {
            let __gitalk__pathname = decodeURI(location.pathname);
            const __gitalk__pathnameLength = __gitalk__pathname.length;
            const __gitalk__pathnameMaxLength = 50;
            if (__gitalk__pathnameLength > __gitalk__pathnameMaxLength) {
                __gitalk__pathname = __gitalk__pathname.substring(0, __gitalk__pathnameMaxLength - 3) + '...';
            }

            try {
                Gitalk && new Gitalk({
                    clientID: '55bad54a77b7e60ad62d',
                    clientSecret: '1031c81500c6be06e338087cb7b713f2d0201b46',
                    repo: 'wait-you.github.io',
                    owner: 'wait-you',
                    admin: ['wait-you'],
                    id: 'comment',
                    language: 'zh-CN'
                }).render('gitalk-container');

            } catch (e) {
                window.Gitalk = null;
            }
        }

        if ('true') {
            const loadGitalkTimeout = setTimeout(() => {
                loadGitalk();
                clearTimeout(loadGitalkTimeout);
            }, 1000);
        } else {
            window.addEventListener('DOMContentLoaded', loadGitalk);
        }
    </script>



        
    
</div>

                </div>
            
        </div>

        
            <div class="toc-content-container">
                <div class="post-toc-wrap">
    <div class="post-toc">
        <div class="toc-title">此页目录</div>
        <div class="page-title">Java最佳实践</div>
        <ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#%E6%9C%80%E4%BD%B3%E5%AE%9E%E8%B7%B5"><span class="nav-text"> 最佳实践</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%88%9D%E5%A7%8B%E5%8C%96gradle%E5%B7%A5%E7%A8%8B%E5%BC%95%E5%85%A5%E5%8D%95%E5%85%83%E6%B5%8B%E8%AF%95"><span class="nav-text"> 初始化 Gradle 工程，引入单元测试</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E8%BD%AF%E4%BB%B6%E8%BF%90%E8%A1%8C%E7%8E%AF%E5%A2%83"><span class="nav-text"> 软件运行环境：</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%88%9D%E5%A7%8B%E5%8C%96gradle%E5%B7%A5%E7%A8%8B"><span class="nav-text"> 初始化 Gradle 工程</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%B7%BB%E5%8A%A0spring%E6%94%AF%E6%8C%81%E8%AE%BE%E7%BD%AE-git-hooks"><span class="nav-text"> 添加 Spring 支持，设置 Git Hooks</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%AF%BC%E5%85%A5%E4%BE%9D%E8%B5%96"><span class="nav-text"> 导入依赖</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E8%AE%BE%E7%BD%AE-githooks"><span class="nav-text"> 设置 GitHooks</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%B5%8B%E8%AF%95"><span class="nav-text"> 测试</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E4%BB%A3%E7%A0%81%E9%9D%99%E6%80%81%E6%A3%80%E6%9F%A5%E6%B5%8B%E8%AF%95%E4%B8%9A%E5%8A%A1%E6%96%B9%E6%B3%95"><span class="nav-text"> 代码静态检查，测试业务方法</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E9%80%9A%E7%94%A8%E9%85%8D%E7%BD%AE%E5%92%8C%E7%8E%AF%E5%A2%83%E9%85%8D%E7%BD%AE%E5%88%86%E7%A6%BB"><span class="nav-text"> 通用配置和环境配置分离</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E9%9D%99%E6%80%81%E6%A3%80%E6%9F%A5"><span class="nav-text"> 静态检查</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E4%B8%9A%E5%8A%A1%E5%BC%80%E5%8F%91"><span class="nav-text"> 业务开发</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#spring-%E6%B3%A8%E5%85%A5"><span class="nav-text"> spring 注入</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E4%BA%8B%E5%8A%A1%E8%BE%B9%E7%95%8C"><span class="nav-text"> 事务边界</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%B5%8B%E8%AF%95-2"><span class="nav-text"> 测试</span></a></li></ol></li></ol></li></ol>

    </div>
</div>
            </div>
        
    </div>
</div>


                

            </div>
            
            

        </div>

        <div class="main-content-footer">
            <footer class="footer">
    <div class="info-container">
        <div class="copyright-info">
            &copy;
            
              <span>2022</span>
              -
            
            2023&nbsp;&nbsp;<i class="fa-solid fa-heart fa-beat" style="--fa-animation-duration: 0.5s; color: #f54545"></i>&nbsp;&nbsp;<a href="/">meteor</a>
        </div>
        
            <script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
            <div class="website-count info-item">
                
                    <span id="busuanzi_container_site_uv" class="busuanzi_container_site_uv">
                        访问人数&nbsp;<span id="busuanzi_value_site_uv" class="busuanzi_value_site_uv"></span>
                    </span>
                
                
                    <span id="busuanzi_container_site_pv" class="busuanzi_container_site_pv">
                        总访问量&nbsp;<span id="busuanzi_value_site_pv" class="busuanzi_value_site_pv"></span>
                    </span>
                
            </div>
        
        <div class="theme-info info-item">
            <span class="powered-by-container">由 <?xml version="1.0" encoding="utf-8"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg version="1.1" id="圖層_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="1rem" height="1rem" viewBox="0 0 512 512" enable-background="new 0 0 512 512" xml:space="preserve"><path fill="#0E83CD" d="M256.4,25.8l-200,115.5L56,371.5l199.6,114.7l200-115.5l0.4-230.2L256.4,25.8z M349,354.6l-18.4,10.7l-18.6-11V275H200v79.6l-18.4,10.7l-18.6-11v-197l18.5-10.6l18.5,10.8V237h112v-79.6l18.5-10.6l18.5,10.8V354.6z"/></svg><a target="_blank" href="https://hexo.io">Hexo</a> 驱动</span>
                <br>
            <span class="theme-version-container">主题&nbsp;<a class="theme-version" target="_blank" href="https://github.com/EvanNotFound/hexo-theme-redefine">Redefine v2.1.4</a>
        </div>
        
            <div class="icp-info info-item"><a target="_blank" rel="nofollow" href="
                
                    beian.miit.gov.cn
                
                ">冀ICP备20010108号</a></div>
        
        
        
            <div id="start_div" style="display:none">
                2022/8/17 11:45:14
            </div>
            <div>
                博客已运行 <span class="odometer" id="runtime_days" ></span> 天 <span class="odometer" id="runtime_hours"></span> 小时 <span class="odometer" id="runtime_minutes"></span> 分钟 <span class="odometer" id="runtime_seconds"></span> 秒
            </div>
        
        
        
            <script async data-pjax>
                try {
                    function odometer_init() {
                    const elements = document.querySelectorAll('.odometer');
                    elements.forEach(el => {
                        new Odometer({
                            el,
                            format: '( ddd).dd',
                            duration: 200
                        });
                    });
                    }
                    odometer_init();
                } catch (error) {}
            </script>
        
        
        
    </div>  
</footer>
        </div>
    </div>

    
        <div class="post-tools">
            <div class="post-tools-container">
    <ul class="article-tools-list">
        <!-- TOC aside toggle -->
        
            <li class="right-bottom-tools page-aside-toggle">
                <i class="fa-regular fa-outdent"></i>
            </li>
        

        <!-- go comment -->
        
            <li class="go-comment">
                <i class="fa-regular fa-comments"></i>
            </li>
        
    </ul>
</div>

        </div>
    

    <div class="right-side-tools-container">
        <div class="side-tools-container">
    <ul class="hidden-tools-list">
        <li class="right-bottom-tools tool-font-adjust-plus flex-center">
            <i class="fa-regular fa-magnifying-glass-plus"></i>
        </li>

        <li class="right-bottom-tools tool-font-adjust-minus flex-center">
            <i class="fa-regular fa-magnifying-glass-minus"></i>
        </li>

        <li class="right-bottom-tools tool-expand-width flex-center">
            <i class="fa-regular fa-expand"></i>
        </li>

        <li class="right-bottom-tools tool-dark-light-toggle flex-center">
            <i class="fa-regular fa-moon"></i>
        </li>

        <!-- rss -->
        

        

        <li class="right-bottom-tools tool-scroll-to-bottom flex-center">
            <i class="fa-regular fa-arrow-down"></i>
        </li>
    </ul>

    <ul class="visible-tools-list">
        <li class="right-bottom-tools toggle-tools-list flex-center">
            <i class="fa-regular fa-cog fa-spin"></i>
        </li>
        
            <li class="right-bottom-tools tool-scroll-to-top flex-center">
                <i class="arrow-up fas fa-arrow-up"></i>
                <span class="percent"></span>
            </li>
        
        
    </ul>
</div>

    </div>

    <div class="image-viewer-container">
    <img src="">
</div>


    


</main>




<script src="/js/utils.js"></script>

<script src="/js/main.js"></script>

<script src="/js/layouts/navbarShrink.js"></script>

<script src="/js/tools/scrollTopBottom.js"></script>

<script src="/js/tools/lightDarkSwitch.js"></script>





    
<script src="/js/tools/codeBlock.js"></script>




    
<script src="/js/layouts/lazyload.js"></script>




    
<script src="/js/tools/runtime.js"></script>

    
<script src="/js/layouts/odometer.min.js"></script>

    
<link rel="stylesheet" href="/assets/odometer-theme-minimal.css">




  
<script src="/js/libs/Typed.min.js"></script>

  
<script src="/js/plugins/typed.js"></script>







<div class="post-scripts pjax">
    
        
<script src="/js/tools/tocToggle.js"></script>

<script src="/js/libs/anime.min.js"></script>

<script src="/js/layouts/toc.js"></script>

<script src="/js/plugins/tabs.js"></script>

    
</div>


    
<script src="/js/libs/pjax.min.js"></script>

<script>
    window.addEventListener('DOMContentLoaded', () => {
        window.pjax = new Pjax({
            selectors: [
                'head title',
                '.page-container',
                '.pjax',
            ],
            history: true,
            debug: false,
            cacheBust: false,
            timeout: 0,
            analytics: false,
            currentUrlFullReload: false,
            scrollRestoration: false,
            // scrollTo: true,
        });

        document.addEventListener('pjax:send', () => {
            Global.utils.pjaxProgressBarStart();
        });

        document.addEventListener('pjax:complete', () => {
            Global.utils.pjaxProgressBarEnd();
            window.pjax.executeScripts(document.querySelectorAll('script[data-pjax], .pjax script'));
            Global.refresh();
        });
    });
</script>




</body>
</html>
